All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] tag: add --points-at list option
@ 2012-02-05 22:28 Tom Grennan
  2012-02-05 23:31 ` Junio C Hamano
  2012-02-06  0:04 ` Jeff King
  0 siblings, 2 replies; 53+ messages in thread
From: Tom Grennan @ 2012-02-05 22:28 UTC (permalink / raw)
  To: git; +Cc: gitster, krh, jasampler

This filters the list for annotated|signed tags of the given object.
Example,

   john$ git tag -s v1.0-john v1.0
   john$ git tag -l --points-at v1.0
   v1.0-john

Signed-off-by: Tom Grennan <tmgrennan@gmail.com>
---
 Documentation/git-tag.txt |    5 +++-
 builtin/tag.c             |   59 ++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 53ff5f6..b9ec75c 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -12,7 +12,7 @@ SYNOPSIS
 'git tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]
 	<tagname> [<commit> | <object>]
 'git tag' -d <tagname>...
-'git tag' [-n[<num>]] -l [--contains <commit>] [<pattern>...]
+'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] [<pattern>...]
 'git tag' -v <tagname>...
 
 DESCRIPTION
@@ -86,6 +86,9 @@ OPTIONS
 --contains <commit>::
 	Only list tags which contain the specified commit.
 
+--points-at <object>::
+	Only list annotated or signed tags of the given object.
+
 -m <msg>::
 --message=<msg>::
 	Use the given tag message (instead of prompting).
diff --git a/builtin/tag.c b/builtin/tag.c
index 31f02e8..7568d6c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,8 @@
 static const char * const git_tag_usage[] = {
 	"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
 	"git tag -d <tagname>...",
-	"git tag -l [-n[<num>]] [<pattern>...]",
+	"git tag -l [-n[<num>]] [<pattern>...] \\\n\t\t"
+		"[--contains <commit>] [--points-at <object>]",
 	"git tag -v <tagname>...",
 	NULL
 };
@@ -28,6 +29,7 @@ struct tag_filter {
 	const char **patterns;
 	int lines;
 	struct commit_list *with_commit;
+	const unsigned char *points_at;
 };
 
 static int match_pattern(const char **patterns, const char *ref)
@@ -105,16 +107,28 @@ static int show_reference(const char *refname, const unsigned char *sha1,
 				return 0;
 		}
 
+		buf = read_sha1_file(sha1, &type, &size);
+		if (!buf || !size)
+			return 0;
+
+		if (filter->points_at) {
+			unsigned char tagged_sha1[20];
+			if (memcmp("object ", buf, 7) \
+			    || buf[47] != '\n' \
+			    || get_sha1_hex(buf + 7, tagged_sha1) \
+			    || memcmp(filter->points_at, tagged_sha1, 20)) {
+				free(buf);
+				return 0;
+			}
+		}
+
 		if (!filter->lines) {
 			printf("%s\n", refname);
+			free(buf);
 			return 0;
 		}
 		printf("%-15s ", refname);
 
-		buf = read_sha1_file(sha1, &type, &size);
-		if (!buf || !size)
-			return 0;
-
 		/* skip header */
 		sp = strstr(buf, "\n\n");
 		if (!sp) {
@@ -143,16 +157,20 @@ static int show_reference(const char *refname, const unsigned char *sha1,
 }
 
 static int list_tags(const char **patterns, int lines,
-			struct commit_list *with_commit)
+			struct commit_list *with_commit,
+			unsigned char *points_at)
 {
 	struct tag_filter filter;
 
 	filter.patterns = patterns;
 	filter.lines = lines;
 	filter.with_commit = with_commit;
+	filter.points_at = points_at;
 
 	for_each_tag_ref(show_reference, (void *) &filter);
 
+	if (points_at)
+		free(points_at);
 	return 0;
 }
 
@@ -375,12 +393,28 @@ static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
 	return check_refname_format(sb->buf, 0);
 }
 
+int parse_opt_points_at(const struct option *opt, const char *arg, int unset)
+{
+	unsigned char *sha1;
+
+	if (!arg)
+		return -1;
+	sha1 = xmalloc(20);
+	if (get_sha1(arg, sha1)) {
+		free(sha1);
+		return error("malformed object name %s", arg);
+	}
+	*(unsigned char **)opt->value = sha1;
+	return 0;
+}
+
 int cmd_tag(int argc, const char **argv, const char *prefix)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct strbuf ref = STRBUF_INIT;
 	unsigned char object[20], prev[20];
 	const char *object_ref, *tag;
+	unsigned char *points_at;
 	struct ref_lock *lock;
 	struct create_tag_options opt;
 	char *cleanup_arg = NULL;
@@ -417,6 +451,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_LASTARG_DEFAULT,
 			parse_opt_with_commit, (intptr_t)"HEAD",
 		},
+		{
+			OPTION_CALLBACK, 0, "points-at", &points_at, "object",
+			"print only annotated|signed tags of the object",
+			PARSE_OPT_LASTARG_DEFAULT,
+			parse_opt_points_at, (intptr_t)"HEAD",
+		},
 		OPT_END()
 	};
 
@@ -443,11 +483,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 		usage_with_options(git_tag_usage, options);
 	if (list)
 		return list_tags(argv, lines == -1 ? 0 : lines,
-				 with_commit);
+				 with_commit, points_at);
 	if (lines != -1)
 		die(_("-n option is only allowed with -l."));
-	if (with_commit)
-		die(_("--contains option is only allowed with -l."));
+	if (with_commit || points_at)
+		die(_("--contains and --points-at options "
+		      "are only allowed with -l."));
 	if (delete)
 		return for_each_tag_name(argv, delete_tag);
 	if (verify)
-- 
1.7.8

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

end of thread, other threads:[~2012-02-09  4:33 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-05 22:28 [RFC/PATCH] tag: add --points-at list option Tom Grennan
2012-02-05 23:31 ` Junio C Hamano
2012-02-06  5:48   ` Tom Grennan
2012-02-06  6:25     ` Junio C Hamano
2012-02-06  6:45       ` Tom Grennan
2012-02-06  0:04 ` Jeff King
2012-02-06  6:32   ` Tom Grennan
2012-02-06  7:04     ` Jeff King
2012-02-06  7:13       ` Jeff King
2012-02-06  7:45         ` Jeff King
2012-02-06  8:11           ` Jeff King
2012-02-06  8:13             ` [PATCH 1/3] tag: fix output of "tag -n" when errors occur Jeff King
2012-02-06  8:13             ` [PATCH 2/3] tag: die when listing missing or corrupt objects Jeff King
2012-02-06  8:32               ` Junio C Hamano
2012-02-06  8:34                 ` Jeff King
2012-02-06  8:36                 ` Junio C Hamano
2012-02-06  8:38                   ` Jeff King
2012-02-06 18:04                     ` Junio C Hamano
2012-02-06 18:13                     ` Junio C Hamano
2012-02-06 20:12                       ` Jeff King
2012-02-06 23:34                         ` Junio C Hamano
2012-02-08 21:01                       ` Jeff King
2012-02-09  4:33                         ` Junio C Hamano
2012-02-06  8:14             ` [PATCH 3/3] tag: don't show non-tag contents with "-n" Jeff King
2012-02-07  7:01             ` [PATCHv2] tag: add --points-at list option Tom Grennan
2012-02-07  7:01             ` Tom Grennan
2012-02-07  8:35               ` Junio C Hamano
2012-02-07 18:05                 ` Tom Grennan
2012-02-07 16:05               ` Jeff King
2012-02-07 19:02                 ` Tom Grennan
2012-02-07 19:12                   ` Jeff King
2012-02-07 19:22                     ` Tom Grennan
2012-02-07 19:36                       ` Jeff King
2012-02-07 20:20                         ` Junio C Hamano
2012-02-07 21:30                           ` Jeff King
2012-02-07 22:08                             ` Tom Grennan
2012-02-08  0:25                               ` Jeff King
2012-02-08  1:45                                 ` Tom Grennan
2012-02-08 15:31                                   ` Jeff King
2012-02-08  6:21                                 ` [PATCHv3] " Tom Grennan
2012-02-08  6:21                                 ` Tom Grennan
2012-02-08 15:44                                   ` Jeff King
2012-02-08 18:43                                     ` Tom Grennan
2012-02-08 18:57                                       ` Jeff King
2012-02-08 20:12                                         ` [PATCHv4] " Tom Grennan
2012-02-08 20:12                                         ` Tom Grennan
2012-02-08 20:58                                           ` Jeff King
2012-02-08 22:15                                             ` Tom Grennan
2012-02-08 23:03                                             ` [PATCH-master] " Tom Grennan
2012-02-08 23:03                                             ` Tom Grennan
2012-02-09  1:44                                               ` Jeff King
2012-02-09  4:29                                                 ` Junio C Hamano
2012-02-08 18:58                                       ` [PATCHv3] " Tom Grennan

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.