X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-tag.c;h=01e73747d02f384c5e31b846340a4b586c84aab3;hb=8321c56b6bae25a2d70790f452df894be536b32c;hp=d339971fab896bda0297f04a4f3961bae27b21be;hpb=6dbcb59e8271c16cbec486932bd3069279e09c60;p=git.git diff --git a/builtin-tag.c b/builtin-tag.c index d339971fa..01e73747d 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -26,6 +26,7 @@ static char signingkey[1000]; struct tag_filter { const char *pattern; int lines; + struct commit_list *with_commit; }; #define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----" @@ -42,6 +43,16 @@ static int show_reference(const char *refname, const unsigned char *sha1, char *buf, *sp, *eol; size_t len; + if (filter->with_commit) { + struct commit *commit; + + commit = lookup_commit_reference_gently(sha1, 1); + if (!commit) + return 0; + if (!is_descendant_of(commit, filter->with_commit)) + return 0; + } + if (!filter->lines) { printf("%s\n", refname); return 0; @@ -79,7 +90,8 @@ static int show_reference(const char *refname, const unsigned char *sha1, return 0; } -static int list_tags(const char *pattern, int lines) +static int list_tags(const char *pattern, int lines, + struct commit_list *with_commit) { struct tag_filter filter; @@ -88,6 +100,7 @@ static int list_tags(const char *pattern, int lines) filter.pattern = pattern; filter.lines = lines; + filter.with_commit = with_commit; for_each_tag_ref(show_reference, (void *) &filter); @@ -253,6 +266,15 @@ static void write_tag_body(int fd, const unsigned char *sha1) free(buf); } +static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result) +{ + if (sign && do_sign(buf) < 0) + return error("unable to sign the tag"); + if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0) + return error("unable to write tag file"); + return 0; +} + static void create_tag(const unsigned char *object, const char *tag, struct strbuf *buf, int message, int sign, unsigned char *prev, unsigned char *result) @@ -260,6 +282,7 @@ static void create_tag(const unsigned char *object, const char *tag, enum object_type type; char header_buf[1024]; int header_len; + char *path = NULL; type = sha1_object_info(object, NULL); if (type <= OBJ_NONE) @@ -279,7 +302,6 @@ static void create_tag(const unsigned char *object, const char *tag, die("tag header too big."); if (!message) { - char *path; int fd; /* write the template message before editing: */ @@ -300,9 +322,6 @@ static void create_tag(const unsigned char *object, const char *tag, "Please supply the message using either -m or -F option.\n"); exit(1); } - - unlink(path); - free(path); } stripspace(buf, 1); @@ -312,10 +331,16 @@ static void create_tag(const unsigned char *object, const char *tag, strbuf_insert(buf, 0, header_buf, header_len); - if (sign && do_sign(buf) < 0) - die("unable to sign the tag"); - if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0) - die("unable to write tag file"); + if (build_tag_object(buf, sign, result) < 0) { + if (path) + fprintf(stderr, "The tag message has been left in %s\n", + path); + exit(128); + } + if (path) { + unlink(path); + free(path); + } } struct msg_arg { @@ -348,6 +373,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) list = 0, delete = 0, verify = 0; const char *msgfile = NULL, *keyid = NULL; struct msg_arg msg = { 0, STRBUF_INIT }; + struct commit_list *with_commit = NULL; struct option options[] = { OPT_BOOLEAN('l', NULL, &list, "list tag names"), { OPTION_INTEGER, 'n', NULL, &lines, NULL, @@ -366,6 +392,14 @@ int cmd_tag(int argc, const char **argv, const char *prefix) OPT_STRING('u', NULL, &keyid, "key-id", "use another key to sign the tag"), OPT_BOOLEAN('f', NULL, &force, "replace the tag if exists"), + + OPT_GROUP("Tag listing options"), + { + OPTION_CALLBACK, 0, "contains", &with_commit, "commit", + "print only tags that contain the commit", + PARSE_OPT_LASTARG_DEFAULT, + parse_opt_with_commit, (intptr_t)"HEAD", + }, OPT_END() }; @@ -390,9 +424,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix) if (list + delete + verify > 1) usage_with_options(git_tag_usage, options); if (list) - return list_tags(argv[0], lines == -1 ? 0 : lines); + return list_tags(argv[0], lines == -1 ? 0 : lines, + with_commit); if (lines != -1) die("-n option is only allowed with -l."); + if (with_commit) + die("--contains option is only allowed with -l."); if (delete) return for_each_tag_name(argv, delete_tag); if (verify)