Expose the verify_tag() function so ‘git tag -v’ can use it directly in the future. verify_tag() already frees all the memory it allocates and does not call any functions that can exit, so this should be safe. The function is renamed to verify_tag_signature() for clarity and to avoid conflicting with builtin/tag.c and builtin/mktag.c’s unrelated verify_tag(). Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- Makefile | 1 + builtin/verify-tag.c | 85 +--------------------------------- tag.h | 1 + builtin/verify-tag.c => verify-tag.c | 34 +------------- 4 files changed, 4 insertions(+), 117 deletions(-) copy builtin/verify-tag.c => verify-tag.c (71%) diff --git a/Makefile b/Makefile index 7c616f8..ed58261 100644 --- a/Makefile +++ b/Makefile @@ -616,6 +616,7 @@ LIB_OBJS += unpack-trees.o LIB_OBJS += usage.o LIB_OBJS += userdiff.o LIB_OBJS += utf8.o +LIB_OBJS += verify-tag.o LIB_OBJS += walker.o LIB_OBJS += wrapper.o LIB_OBJS += write_or_die.o diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 91dd1c1..ca075bd 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -5,12 +5,8 @@ * * Based on git-verify-tag.sh */ -#include "cache.h" #include "builtin.h" #include "tag.h" -#include "run-command.h" -#include <signal.h> -#include "sigchain.h" #include "parse-options.h" static const char * const verify_tag_usage[] = { @@ -18,85 +14,6 @@ static const char * const verify_tag_usage[] = { NULL }; -#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----" - -static int run_gpg_verify(const char *buf, unsigned long size, int verbose) -{ - struct child_process gpg; - const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL}; - char path[PATH_MAX], *eol; - size_t len; - int fd, ret; - - fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX"); - if (fd < 0) - return error("could not create temporary file '%s': %s", - path, strerror(errno)); - if (write_in_full(fd, buf, size) < 0) - return error("failed writing temporary file '%s': %s", - path, strerror(errno)); - close(fd); - - /* find the length without signature */ - len = 0; - while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) { - eol = memchr(buf + len, '\n', size - len); - len += eol ? eol - (buf + len) + 1 : size - len; - } - if (verbose) - write_in_full(1, buf, len); - - memset(&gpg, 0, sizeof(gpg)); - gpg.argv = args_gpg; - gpg.in = -1; - args_gpg[2] = path; - if (start_command(&gpg)) { - unlink(path); - return error("could not run gpg."); - } - - /* - * gpg will stop as soon as it knows the signature is bad, - * which can result in SIGPIPE. - */ - sigchain_push(SIGPIPE, SIG_IGN); - write_in_full(gpg.in, buf, len); - close(gpg.in); - sigchain_pop(SIGPIPE); - - ret = finish_command(&gpg); - - unlink_or_warn(path); - - return ret; -} - -static int verify_tag(const char *name, int verbose) -{ - enum object_type type; - unsigned char sha1[20]; - char *buf; - unsigned long size; - int ret; - - if (get_sha1(name, sha1)) - return error("tag '%s' not found.", name); - - type = sha1_object_info(sha1, NULL); - if (type != OBJ_TAG) - return error("%s: cannot verify a non-tag object of type %s.", - name, typename(type)); - - buf = read_sha1_file(sha1, &type, &size); - if (!buf) - return error("%s: unable to read file.", name); - - ret = run_gpg_verify(buf, size, verbose); - - free(buf); - return ret; -} - int cmd_verify_tag(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -113,7 +30,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) usage_with_options(verify_tag_usage, verify_tag_options); while (i < argc) - if (verify_tag(argv[i++], verbose)) + if (verify_tag_signature(argv[i++], verbose)) had_error = 1; return had_error; } diff --git a/tag.h b/tag.h index 7a0cb00..1034109 100644 --- a/tag.h +++ b/tag.h @@ -16,5 +16,6 @@ extern struct tag *lookup_tag(const unsigned char *sha1); extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size); extern int parse_tag(struct tag *item); extern struct object *deref_tag(struct object *, const char *, int); +extern int verify_tag_signature(const char *name, int verbose); #endif /* TAG_H */ diff --git a/builtin/verify-tag.c b/verify-tag.c similarity index 71% copy from builtin/verify-tag.c copy to verify-tag.c index 91dd1c1..7152e99 100644 --- a/builtin/verify-tag.c +++ b/verify-tag.c @@ -1,22 +1,11 @@ /* - * Builtin "git verify-tag" - * * Copyright (c) 2007 Carlos Rica <jasampler@xxxxxxxxx> - * - * Based on git-verify-tag.sh */ #include "cache.h" -#include "builtin.h" #include "tag.h" #include "run-command.h" #include <signal.h> #include "sigchain.h" -#include "parse-options.h" - -static const char * const verify_tag_usage[] = { - "git verify-tag [-v|--verbose] <tag>...", - NULL -}; #define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----" @@ -71,7 +60,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose) return ret; } -static int verify_tag(const char *name, int verbose) +int verify_tag_signature(const char *name, int verbose) { enum object_type type; unsigned char sha1[20]; @@ -96,24 +85,3 @@ static int verify_tag(const char *name, int verbose) free(buf); return ret; } - -int cmd_verify_tag(int argc, const char **argv, const char *prefix) -{ - int i = 1, verbose = 0, had_error = 0; - const struct option verify_tag_options[] = { - OPT__VERBOSE(&verbose), - OPT_END() - }; - - git_config(git_default_config, NULL); - - argc = parse_options(argc, argv, prefix, verify_tag_options, - verify_tag_usage, PARSE_OPT_KEEP_ARGV0); - if (argc <= i) - usage_with_options(verify_tag_usage, verify_tag_options); - - while (i < argc) - if (verify_tag(argv[i++], verbose)) - had_error = 1; - return had_error; -} -- 1.7.0.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html