All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tag: add -i and --introduced modifier for --contains
@ 2014-04-16 20:58 Luis R. Rodriguez
  2014-04-16 22:02 ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: Luis R. Rodriguez @ 2014-04-16 20:58 UTC (permalink / raw)
  To: git; +Cc: Luis R. Rodriguez, Jiri Slaby, Andreas Schwab, Jan Kara

From: "Luis R. Rodriguez" <mcgrof@suse.com>

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@suse.cz>
Cc: Andreas Schwab <schwab@suse.de>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-04-22 17:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-16 20:58 [PATCH] tag: add -i and --introduced modifier for --contains Luis R. Rodriguez
2014-04-16 22:02 ` Junio C Hamano
2014-04-16 22:35   ` Luis R. Rodriguez
2014-04-17 17:04     ` Junio C Hamano
2014-04-17 22:16       ` Jeff King
2014-04-18 16:26         ` Junio C Hamano
2014-04-22  4:04         ` W. Trevor King
2014-04-18 23:17       ` Luis R. Rodriguez
2014-04-18 23:36         ` Junio C Hamano
2014-04-22  0:38           ` Luis R. Rodriguez
2014-04-22 10:27       ` Jan Kara
2014-04-22 17:58         ` Junio C Hamano
2014-04-17  7:17   ` Andreas Schwab
2014-04-17 17:05     ` Junio C Hamano
2014-04-17 17:30       ` Andreas Schwab
2014-04-17 18:49         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.