From: "Luis R. Rodriguez" <mcgrof@xxxxxxxx> Upstream Linux kernel commit c5905afb was introduced on v3.4 but git describe --contains yields v3.5 while if we use git to look for the first parent with git describe --first-parent yields v3.3. The reason for this seems to be that the merge commit that introduced c5905afb was based on v3.3. At least for --contains its unclear to me why we get v3.5, the result is not intuitive, as for --first-parent the issue is that the first parent actually *is* v3.3. The easiest way to address this it to rely on on the git tag --contains implmenetation and add a modifier that specifies you want the tag that first introduced the specified commit. mcgrof@ergon ~/linux (git::master)$ git tag -i --contains c5905afb v3.4 mcgrof@ergon ~/linux (git::master)$ git tag --introduced --contains c5905afb v3.4 Cc: Jiri Slaby <jslaby@xxxxxxx> Cc: Andreas Schwab <schwab@xxxxxxx> Cc: Jan Kara <jack@xxxxxxx> Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxx> --- builtin/tag.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index 6c7c6bd..65a939b 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -21,7 +21,7 @@ static const char * const git_tag_usage[] = { N_("git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]"), N_("git tag -d <tagname>..."), - N_("git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>] " + N_("git tag -l [-n[<num>]] [--contains <commit>] [ -i | --introduced --contains <commit> ] [--points-at <object>] " "\n\t\t[<pattern>...]"), N_("git tag -v <tagname>..."), NULL @@ -195,13 +195,18 @@ static int sort_by_version(const void *a_, const void *b_) } static int list_tags(const char **patterns, int lines, - struct commit_list *with_commit, int sort) + struct commit_list *with_commit, int sort, + int introduced) { struct tag_filter filter; filter.patterns = patterns; filter.lines = lines; - filter.sort = sort; + if (introduced) { + sort = VERCMP_SORT; + filter.sort = sort; + } else + filter.sort = sort; filter.with_commit = with_commit; memset(&filter.tags, 0, sizeof(filter.tags)); filter.tags.strdup_strings = 1; @@ -216,8 +221,11 @@ static int list_tags(const char **patterns, int lines, for (i = filter.tags.nr - 1; i >= 0; i--) printf("%s\n", filter.tags.items[i].string); else - for (i = 0; i < filter.tags.nr; i++) + for (i = 0; i < filter.tags.nr; i++) { printf("%s\n", filter.tags.items[i].string); + if (introduced) + break; + } string_list_clear(&filter.tags, 0); } return 0; @@ -493,6 +501,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) char *cleanup_arg = NULL; int annotate = 0, force = 0, lines = -1; int cmdmode = 0, sort = 0; + int introduced = 0; const char *msgfile = NULL, *keyid = NULL; struct msg_arg msg = { 0, STRBUF_INIT }; struct commit_list *with_commit = NULL; @@ -511,6 +520,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) N_("tag message"), parse_msg_arg), OPT_FILENAME('F', "file", &msgfile, N_("read message from file")), OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")), + OPT_BOOL('i', "introduced", &introduced, N_("print the first tag that introduced the commit")), OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"), N_("how to strip spaces and #comments from message")), OPT_STRING('u', "local-user", &keyid, N_("key-id"), @@ -576,7 +586,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) } if (lines != -1 && sort) die(_("--sort and -n are incompatible")); - ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit, sort); + ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit, + sort, introduced); if (column_active(colopts)) stop_column_filter(); return ret; -- 1.9.0 -- 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