git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v5 0/7] Add --format to tag verification
@ 2017-01-15 18:46 santiago
  2017-01-15 18:46 ` [PATCH v5 1/7] gpg-interface, tag: add GPG_VERIFY_QUIET flag santiago
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: santiago @ 2017-01-15 18:46 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Santiago Torres

From: Santiago Torres <santiago@nyu.edu>

This is the fifth iteration of [1][2][3][4], and as a result of the
discussion in [5]. The main goal of this patch series is to bring
--format to git tag verification so that upper-layer tools can inspect
the content of a tag and make decisions based on it.

In this re-woll we:

* Squashed Peff's first patch[6] with the second patch of the series. The commit
  message may need work.

* Applied the relevant segment's of Peff's second patch[7] on the rest of the
  series

* Rebased so these patches apply to the tip of the master branch.

Thanks,
-Santiago

[1] http://public-inbox.org/git/20161007210721.20437-1-santiago@nyu.edu/
[2] http://public-inbox.org/git/20160930221806.3398-1-santiago@nyu.edu/
[3] http://public-inbox.org/git/20160922185317.349-1-santiago@nyu.edu/
[4] http://public-inbox.org/git/20160926224233.32702-1-santiago@nyu.edu/
[5] http://public-inbox.org/git/20160607195608.16643-1-santiago@nyu.edu/
[6] http://public-inbox.org/git/20161019203546.dfqmi2czcxopgj6w@sigill.intra.peff.net/
[7] http://public-inbox.org/git/20161019203943.epjxnfci7vcqg4xv@sigill.intra.peff.net/

Lukas Puehringer (4):
  gpg-interface, tag: add GPG_VERIFY_QUIET flag
  ref-filter: add function to print single ref_array_item
  tag: add format specifier to gpg_verify_tag
  builtin/tag: add --format argument for tag -v

Santiago Torres (3):
  builtin/verify-tag: add --format to verify-tag
  t/t7030-verify-tag: Add --format specifier tests
  t/t7004-tag: Add --format specifier tests

 Documentation/git-tag.txt        |  2 +-
 Documentation/git-verify-tag.txt |  2 +-
 builtin/tag.c                    | 32 ++++++++++++++++++++++----------
 builtin/verify-tag.c             | 13 +++++++++++--
 gpg-interface.h                  |  1 +
 ref-filter.c                     | 27 +++++++++++++++++++++------
 ref-filter.h                     |  7 +++++++
 t/t7004-tag.sh                   | 16 ++++++++++++++++
 t/t7030-verify-tag.sh            | 16 ++++++++++++++++
 tag.c                            | 22 +++++++++++++++-------
 tag.h                            |  4 ++--
 11 files changed, 113 insertions(+), 29 deletions(-)

-- 
2.11.0


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

* [PATCH v5 1/7] gpg-interface, tag: add GPG_VERIFY_QUIET flag
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
@ 2017-01-15 18:46 ` santiago
  2017-01-15 18:47 ` [PATCH v5 2/7] ref-filter: add function to print single ref_array_item santiago
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: santiago @ 2017-01-15 18:46 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Lukas Puehringer

From: Lukas Puehringer <luk.puehringer@gmail.com>

Functions that print git object information may require that the
gpg-interface functions be silent. Add GPG_VERIFY_QUIET flag and prevent
print_signature_buffer from being called if flag is set.

Signed-off-by: Lukas Puehringer <luk.puehringer@gmail.com>
---
 gpg-interface.h | 1 +
 tag.c           | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gpg-interface.h b/gpg-interface.h
index ea68885ad..85dc9820d 100644
--- a/gpg-interface.h
+++ b/gpg-interface.h
@@ -3,6 +3,7 @@
 
 #define GPG_VERIFY_VERBOSE	1
 #define GPG_VERIFY_RAW		2
+#define GPG_VERIFY_QUIET	4
 
 struct signature_check {
 	char *payload;
diff --git a/tag.c b/tag.c
index d1dcd18cd..291073f6e 100644
--- a/tag.c
+++ b/tag.c
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
+#include "gpg-interface.h"
 
 const char *tag_type = "tag";
 
@@ -24,7 +25,9 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
 
 	ret = check_signature(buf, payload_size, buf + payload_size,
 				size - payload_size, &sigc);
-	print_signature_buffer(&sigc, flags);
+
+	if (!(flags & GPG_VERIFY_QUIET))
+		print_signature_buffer(&sigc, flags);
 
 	signature_check_clear(&sigc);
 	return ret;
-- 
2.11.0


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

* [PATCH v5 2/7] ref-filter: add function to print single ref_array_item
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
  2017-01-15 18:46 ` [PATCH v5 1/7] gpg-interface, tag: add GPG_VERIFY_QUIET flag santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-15 18:47 ` [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag santiago
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Lukas Puehringer

From: Lukas Puehringer <luk.puehringer@gmail.com>

ref-filter functions are useful for printing git object information
using a format specifier. However, some other modules may not want to use
this functionality on a ref-array but only print a single item.

Expose a pretty_print_ref function to create, pretty print and free
individual ref-items.

Signed-off-by: Lukas Puehringer <luk.puehringer@gmail.com>
---
 ref-filter.c | 27 +++++++++++++++++++++------
 ref-filter.h |  7 +++++++
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 1a978405e..5f4b08792 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1361,7 +1361,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 	return ref;
 }
 
-static int filter_ref_kind(struct ref_filter *filter, const char *refname)
+static int ref_kind_from_refname(const char *refname)
 {
 	unsigned int i;
 
@@ -1374,11 +1374,7 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
 		{ "refs/tags/", FILTER_REFS_TAGS}
 	};
 
-	if (filter->kind == FILTER_REFS_BRANCHES ||
-	    filter->kind == FILTER_REFS_REMOTES ||
-	    filter->kind == FILTER_REFS_TAGS)
-		return filter->kind;
-	else if (!strcmp(refname, "HEAD"))
+	if (!strcmp(refname, "HEAD"))
 		return FILTER_REFS_DETACHED_HEAD;
 
 	for (i = 0; i < ARRAY_SIZE(ref_kind); i++) {
@@ -1389,6 +1385,15 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
 	return FILTER_REFS_OTHERS;
 }
 
+static int filter_ref_kind(struct ref_filter *filter, const char *refname)
+{
+	if (filter->kind == FILTER_REFS_BRANCHES ||
+	    filter->kind == FILTER_REFS_REMOTES ||
+	    filter->kind == FILTER_REFS_TAGS)
+		return filter->kind;
+	return ref_kind_from_refname(refname);
+}
+
 /*
  * A call-back given to for_each_ref().  Filter refs and keep them for
  * later object processing.
@@ -1671,6 +1676,16 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
 	putchar('\n');
 }
 
+void pretty_print_ref(const char *name, const unsigned char *sha1,
+		const char *format)
+{
+	struct ref_array_item *ref_item;
+	ref_item = new_ref_array_item(name, sha1, 0);
+	ref_item->kind = ref_kind_from_refname(name);
+	show_ref_array_item(ref_item, format, 0);
+	free_array_item(ref_item);
+}
+
 /*  If no sorting option is given, use refname to sort as default */
 struct ref_sorting *ref_default_sorting(void)
 {
diff --git a/ref-filter.h b/ref-filter.h
index fc55fa357..7b05592ba 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -109,4 +109,11 @@ struct ref_sorting *ref_default_sorting(void);
 /*  Function to parse --merged and --no-merged options */
 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
 
+/*
+ * Print a single ref, outside of any ref-filter. Note that the
+ * name must be a fully qualified refname.
+ */
+void pretty_print_ref(const char *name, const unsigned char *sha1,
+		const char *format);
+
 #endif /*  REF_FILTER_H  */
-- 
2.11.0


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

* [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
  2017-01-15 18:46 ` [PATCH v5 1/7] gpg-interface, tag: add GPG_VERIFY_QUIET flag santiago
  2017-01-15 18:47 ` [PATCH v5 2/7] ref-filter: add function to print single ref_array_item santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-17 15:24   ` Jeff King
  2017-01-15 18:47 ` [PATCH v5 4/7] builtin/verify-tag: add --format to verify-tag santiago
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Lukas Puehringer

From: Lukas Puehringer <luk.puehringer@gmail.com>

Calling functions for gpg_verify_tag() may desire to print relevant
information about the header for further verification. Add an optional
format argument to print any desired information after GPG verification.

Signed-off-by: Lukas Puehringer <luk.puehringer@gmail.com>
---
 builtin/tag.c        |  2 +-
 builtin/verify-tag.c |  2 +-
 tag.c                | 17 +++++++++++------
 tag.h                |  4 ++--
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 73df72811..880677df5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -105,7 +105,7 @@ static int delete_tag(const char *name, const char *ref,
 static int verify_tag(const char *name, const char *ref,
 				const unsigned char *sha1)
 {
-	return gpg_verify_tag(sha1, name, GPG_VERIFY_VERBOSE);
+	return verify_and_format_tag(sha1, name, NULL, GPG_VERIFY_VERBOSE);
 }
 
 static int do_sign(struct strbuf *buffer)
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 99f8148cf..de10198c4 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -51,7 +51,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		const char *name = argv[i++];
 		if (get_sha1(name, sha1))
 			had_error = !!error("tag '%s' not found.", name);
-		else if (gpg_verify_tag(sha1, name, flags))
+		else if (verify_and_format_tag(sha1, name, NULL, flags))
 			had_error = 1;
 	}
 	return had_error;
diff --git a/tag.c b/tag.c
index 291073f6e..d5a7cfb20 100644
--- a/tag.c
+++ b/tag.c
@@ -4,6 +4,7 @@
 #include "tree.h"
 #include "blob.h"
 #include "gpg-interface.h"
+#include "ref-filter.h"
 
 const char *tag_type = "tag";
 
@@ -33,8 +34,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
 	return ret;
 }
 
-int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report,
-		unsigned flags)
+int verify_and_format_tag(const unsigned char *sha1, const char *name,
+		const char *fmt_pretty, unsigned flags)
 {
 	enum object_type type;
 	char *buf;
@@ -44,21 +45,25 @@ int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report,
 	type = sha1_object_info(sha1, NULL);
 	if (type != OBJ_TAG)
 		return error("%s: cannot verify a non-tag object of type %s.",
-				name_to_report ?
-				name_to_report :
+				name ?
+				name :
 				find_unique_abbrev(sha1, DEFAULT_ABBREV),
 				typename(type));
 
 	buf = read_sha1_file(sha1, &type, &size);
 	if (!buf)
 		return error("%s: unable to read file.",
-				name_to_report ?
-				name_to_report :
+				name ?
+				name :
 				find_unique_abbrev(sha1, DEFAULT_ABBREV));
 
 	ret = run_gpg_verify(buf, size, flags);
 
 	free(buf);
+
+	if (fmt_pretty)
+		pretty_print_ref(name, sha1, fmt_pretty);
+
 	return ret;
 }
 
diff --git a/tag.h b/tag.h
index a5721b673..896b9c2dc 100644
--- a/tag.h
+++ b/tag.h
@@ -17,7 +17,7 @@ extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long si
 extern int parse_tag(struct tag *item);
 extern struct object *deref_tag(struct object *, const char *, int);
 extern struct object *deref_tag_noverify(struct object *);
-extern int gpg_verify_tag(const unsigned char *sha1,
-		const char *name_to_report, unsigned flags);
+extern int verify_and_format_tag(const unsigned char *sha1, const char *name,
+		const char *fmt_pretty, unsigned flags);
 
 #endif /* TAG_H */
-- 
2.11.0


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

* [PATCH v5 4/7] builtin/verify-tag: add --format to verify-tag
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
                   ` (2 preceding siblings ...)
  2017-01-15 18:47 ` [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-15 18:47 ` [PATCH v5 5/7] builtin/tag: add --format argument for tag -v santiago
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Santiago Torres

From: Santiago Torres <santiago@nyu.edu>

Callers of verify-tag may want to cross-check the tagname from refs/tags
with the tagname from the tag object header upon GPG verification. This
is to avoid tag refs that point to an incorrect object.

Add a --format parameter to git verify-tag to print the formatted tag
object header in addition to or instead of the --verbose or --raw GPG
verification output.

Signed-off-by: Santiago Torres <santiago@nyu.edu>
---
 Documentation/git-verify-tag.txt |  2 +-
 builtin/verify-tag.c             | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-verify-tag.txt b/Documentation/git-verify-tag.txt
index d590edceb..0b8075dad 100644
--- a/Documentation/git-verify-tag.txt
+++ b/Documentation/git-verify-tag.txt
@@ -8,7 +8,7 @@ git-verify-tag - Check the GPG signature of tags
 SYNOPSIS
 --------
 [verse]
-'git verify-tag' <tag>...
+'git verify-tag' [--format=<format>] <tag>...
 
 DESCRIPTION
 -----------
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index de10198c4..212449f47 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -12,12 +12,14 @@
 #include <signal.h>
 #include "parse-options.h"
 #include "gpg-interface.h"
+#include "ref-filter.h"
 
 static const char * const verify_tag_usage[] = {
-		N_("git verify-tag [-v | --verbose] <tag>..."),
+		N_("git verify-tag [-v | --verbose] [--format=<format>] <tag>..."),
 		NULL
 };
 
+
 static int git_verify_tag_config(const char *var, const char *value, void *cb)
 {
 	int status = git_gpg_config(var, value, cb);
@@ -30,9 +32,11 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
+	char *fmt_pretty = NULL;
 	const struct option verify_tag_options[] = {
 		OPT__VERBOSE(&verbose, N_("print tag contents")),
 		OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
+		OPT_STRING(  0 , "format", &fmt_pretty, N_("format"), N_("format to use for the output")),
 		OPT_END()
 	};
 
@@ -46,12 +50,17 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	if (verbose)
 		flags |= GPG_VERIFY_VERBOSE;
 
+	if (fmt_pretty) {
+		verify_ref_format(fmt_pretty);
+		flags |= GPG_VERIFY_QUIET;
+	}
+
 	while (i < argc) {
 		unsigned char sha1[20];
 		const char *name = argv[i++];
 		if (get_sha1(name, sha1))
 			had_error = !!error("tag '%s' not found.", name);
-		else if (verify_and_format_tag(sha1, name, NULL, flags))
+		else if (verify_and_format_tag(sha1, name, fmt_pretty, flags))
 			had_error = 1;
 	}
 	return had_error;
-- 
2.11.0


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

* [PATCH v5 5/7] builtin/tag: add --format argument for tag -v
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
                   ` (3 preceding siblings ...)
  2017-01-15 18:47 ` [PATCH v5 4/7] builtin/verify-tag: add --format to verify-tag santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-17 15:34   ` Jeff King
  2017-01-15 18:47 ` [PATCH v5 6/7] t/t7030-verify-tag: Add --format specifier tests santiago
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Lukas Puehringer

From: Lukas Puehringer <luk.puehringer@gmail.com>

Adding --format to git tag -v mutes the default output of the GPG
verification and instead prints the formatted tag object.
This allows callers to cross-check the tagname from refs/tags with
the tagname from the tag object header upon GPG verification.

The callback function for for_each_tag_name() didn't allow callers to
pass custom data to their callback functions. Add a new opaque pointer
to each_tag_name_fn's parameter to allow this.

Signed-off-by: Lukas Puehringer <luk.puehringer@gmail.com>
---
 Documentation/git-tag.txt |  2 +-
 builtin/tag.c             | 32 ++++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 76cfe40d9..586aaa315 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -15,7 +15,7 @@ SYNOPSIS
 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
 	[--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>]
 	[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]
-'git tag' -v <tagname>...
+'git tag' -v [--format=<format>] <tagname>...
 
 DESCRIPTION
 -----------
diff --git a/builtin/tag.c b/builtin/tag.c
index 880677df5..9da11e0c2 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -24,7 +24,7 @@ static const char * const git_tag_usage[] = {
 	N_("git tag -d <tagname>..."),
 	N_("git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>]"
 		"\n\t\t[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]"),
-	N_("git tag -v <tagname>..."),
+	N_("git tag -v [--format=<format>] <tagname>..."),
 	NULL
 };
 
@@ -66,15 +66,17 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con
 }
 
 typedef int (*each_tag_name_fn)(const char *name, const char *ref,
-				const unsigned char *sha1);
+				const unsigned char *sha1, void *cb_data);
 
-static int for_each_tag_name(const char **argv, each_tag_name_fn fn)
+static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
+		void *cb_data)
 {
 	const char **p;
 	char ref[PATH_MAX];
 	int had_error = 0;
 	unsigned char sha1[20];
 
+
 	for (p = argv; *p; p++) {
 		if (snprintf(ref, sizeof(ref), "refs/tags/%s", *p)
 					>= sizeof(ref)) {
@@ -87,14 +89,14 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn)
 			had_error = 1;
 			continue;
 		}
-		if (fn(*p, ref, sha1))
+		if (fn(*p, ref, sha1, cb_data))
 			had_error = 1;
 	}
 	return had_error;
 }
 
 static int delete_tag(const char *name, const char *ref,
-				const unsigned char *sha1)
+				const unsigned char *sha1, void *cb_data)
 {
 	if (delete_ref(ref, sha1, 0))
 		return 1;
@@ -103,9 +105,16 @@ static int delete_tag(const char *name, const char *ref,
 }
 
 static int verify_tag(const char *name, const char *ref,
-				const unsigned char *sha1)
+				const unsigned char *sha1, void *cb_data)
 {
-	return verify_and_format_tag(sha1, name, NULL, GPG_VERIFY_VERBOSE);
+	int flags;
+	char *fmt_pretty = cb_data;
+	flags = GPG_VERIFY_VERBOSE;
+
+	if (fmt_pretty)
+		flags = GPG_VERIFY_QUIET;
+
+	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
 }
 
 static int do_sign(struct strbuf *buffer)
@@ -428,9 +437,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (filter.merge_commit)
 		die(_("--merged and --no-merged option are only allowed with -l"));
 	if (cmdmode == 'd')
-		return for_each_tag_name(argv, delete_tag);
-	if (cmdmode == 'v')
-		return for_each_tag_name(argv, verify_tag);
+		return for_each_tag_name(argv, delete_tag, NULL);
+	if (cmdmode == 'v') {
+		if (format)
+			verify_ref_format(format);
+		return for_each_tag_name(argv, verify_tag, format);
+	}
 
 	if (msg.given || msgfile) {
 		if (msg.given && msgfile)
-- 
2.11.0


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

* [PATCH v5 6/7] t/t7030-verify-tag: Add --format specifier tests
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
                   ` (4 preceding siblings ...)
  2017-01-15 18:47 ` [PATCH v5 5/7] builtin/tag: add --format argument for tag -v santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-15 18:47 ` [PATCH v5 7/7] t/t7004-tag: " santiago
  2017-01-17 15:36 ` [PATCH v5 0/7] Add --format to tag verification Jeff King
  7 siblings, 0 replies; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Santiago Torres

From: Santiago Torres <santiago@nyu.edu>

Verify-tag now provides --format specifiers to inspect and ensure the
contents of the tag are proper. We add two tests to ensure this
functionality works as expected: the return value should indicate if
verification passed, and the format specifiers must be respected.

Signed-off-by: Santiago Torres <santiago@nyu.edu>
---
 t/t7030-verify-tag.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh
index 07079a41c..d62ccbb98 100755
--- a/t/t7030-verify-tag.sh
+++ b/t/t7030-verify-tag.sh
@@ -125,4 +125,20 @@ test_expect_success GPG 'verify multiple tags' '
 	test_cmp expect.stderr actual.stderr
 '
 
+test_expect_success 'verifying tag with --format' '
+	cat >expect <<-\EOF
+	tagname : fourth-signed
+	EOF &&
+	git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
+	cat >expect <<-\EOF
+	tagname : 7th forged-signed
+	EOF &&
+	test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
+	test_cmp expect actual-forged
+'
+
 test_done
-- 
2.11.0


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

* [PATCH v5 7/7] t/t7004-tag: Add --format specifier tests
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
                   ` (5 preceding siblings ...)
  2017-01-15 18:47 ` [PATCH v5 6/7] t/t7030-verify-tag: Add --format specifier tests santiago
@ 2017-01-15 18:47 ` santiago
  2017-01-17 15:35   ` Jeff King
  2017-01-17 15:36 ` [PATCH v5 0/7] Add --format to tag verification Jeff King
  7 siblings, 1 reply; 21+ messages in thread
From: santiago @ 2017-01-15 18:47 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, sunshine, walters, Santiago Torres

From: Santiago Torres <santiago@nyu.edu>

tag -v now supports --format specifiers to inspect the contents of a tag
upon verification. Add two tests to ensure this behavior is respected in
future changes.

Signed-off-by: Santiago Torres <santiago@nyu.edu>
---
 t/t7004-tag.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 07869b0c0..b2b81f203 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -874,6 +874,22 @@ test_expect_success GPG 'verifying a forged tag should fail' '
 	test_must_fail git tag -v forged-tag
 '
 
+test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
+	cat >expect <<-\EOF 
+	tagname : signed-tag
+	EOF &&
+	git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
+	cat >expect <<-\EOF 
+	tagname : forged-tag
+	EOF &&
+	test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
+	test_cmp expect actual
+'
+
 # blank and empty messages for signed tags:
 
 get_tag_header empty-signed-tag $commit commit $time >expect
-- 
2.11.0


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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-15 18:47 ` [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag santiago
@ 2017-01-17 15:24   ` Jeff King
  2017-01-17 15:30     ` Jeff King
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 15:24 UTC (permalink / raw)
  To: santiago; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Sun, Jan 15, 2017 at 01:47:01PM -0500, santiago@nyu.edu wrote:

> From: Lukas Puehringer <luk.puehringer@gmail.com>
> 
> Calling functions for gpg_verify_tag() may desire to print relevant
> information about the header for further verification. Add an optional
> format argument to print any desired information after GPG verification.

Hrm. Maybe I am missing something, but what does:

  verify_and_format_tag(sha1, name, fmt, flags);

get you over:

  gpg_verify_tag(sha1, name, flags);
  pretty_print_ref(name, sha1, fmt);

? The latter seems much more flexible, and I do not see how the
verification step impacts the printing at all (or vice versa).

I could understand it more if there were patches later in the series
that somehow used the format and verification results together. But I
didn't see that.

-Peff

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 15:24   ` Jeff King
@ 2017-01-17 15:30     ` Jeff King
  2017-01-17 16:57       ` Santiago Torres
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 15:30 UTC (permalink / raw)
  To: santiago; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Tue, Jan 17, 2017 at 10:24:55AM -0500, Jeff King wrote:

> On Sun, Jan 15, 2017 at 01:47:01PM -0500, santiago@nyu.edu wrote:
> 
> > From: Lukas Puehringer <luk.puehringer@gmail.com>
> > 
> > Calling functions for gpg_verify_tag() may desire to print relevant
> > information about the header for further verification. Add an optional
> > format argument to print any desired information after GPG verification.
> 
> Hrm. Maybe I am missing something, but what does:
> 
>   verify_and_format_tag(sha1, name, fmt, flags);
> 
> get you over:
> 
>   gpg_verify_tag(sha1, name, flags);
>   pretty_print_ref(name, sha1, fmt);
> 
> ? The latter seems much more flexible, and I do not see how the
> verification step impacts the printing at all (or vice versa).
> 
> I could understand it more if there were patches later in the series
> that somehow used the format and verification results together. But I
> didn't see that.

Having read through the rest of the series, it looks like you'd
sometimes have to do:

  int ret;

  ret = gpg_verify_tag(sha1, name, flags);
  pretty_print_ref(name, sha1, fmt);
  if (ret)
      ... do something ...

and this function lets you do it in a single line.

Still, I think I'd rather see it done as a wrapper than modifying
gpg_verify_tag().

-Peff

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

* Re: [PATCH v5 5/7] builtin/tag: add --format argument for tag -v
  2017-01-15 18:47 ` [PATCH v5 5/7] builtin/tag: add --format argument for tag -v santiago
@ 2017-01-17 15:34   ` Jeff King
  2017-01-17 17:00     ` Santiago Torres
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 15:34 UTC (permalink / raw)
  To: santiago; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Sun, Jan 15, 2017 at 01:47:03PM -0500, santiago@nyu.edu wrote:

> -static int for_each_tag_name(const char **argv, each_tag_name_fn fn)
> +static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
> +		void *cb_data)
>  {
>  	const char **p;
>  	char ref[PATH_MAX];
>  	int had_error = 0;
>  	unsigned char sha1[20];
>  
> +
>  	for (p = argv; *p; p++) {
>  		if (snprintf(ref, sizeof(ref), "refs/tags/%s", *p)
>  					>= sizeof(ref)) {

Funny extra line?

>  {
> -	return verify_and_format_tag(sha1, name, NULL, GPG_VERIFY_VERBOSE);
> +	int flags;
> +	char *fmt_pretty = cb_data;
> +	flags = GPG_VERIFY_VERBOSE;
> +
> +	if (fmt_pretty)
> +		flags = GPG_VERIFY_QUIET;
> +
> +	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);

It seems funny that VERBOSE and QUIET are bit-flags. What happens when
you ask for GPG_VERIFY_VERBOSE|GPG_VERIFY_QUIET?

I suppose this is actually not a problem in _this_ patch, but in the
very first one that adds the QUIET flag. I'm not sure if the problem is
that the options should be more orthogonal, or that they are just badly
named to appear as opposites when they aren't.

-Peff

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

* Re: [PATCH v5 7/7] t/t7004-tag: Add --format specifier tests
  2017-01-15 18:47 ` [PATCH v5 7/7] t/t7004-tag: " santiago
@ 2017-01-17 15:35   ` Jeff King
  0 siblings, 0 replies; 21+ messages in thread
From: Jeff King @ 2017-01-17 15:35 UTC (permalink / raw)
  To: santiago; +Cc: git, gitster, sunshine, walters

On Sun, Jan 15, 2017 at 01:47:05PM -0500, santiago@nyu.edu wrote:

> From: Santiago Torres <santiago@nyu.edu>
> 
> tag -v now supports --format specifiers to inspect the contents of a tag
> upon verification. Add two tests to ensure this behavior is respected in
> future changes.
> 
> Signed-off-by: Santiago Torres <santiago@nyu.edu>
> ---
>  t/t7004-tag.sh | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> index 07869b0c0..b2b81f203 100755
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -874,6 +874,22 @@ test_expect_success GPG 'verifying a forged tag should fail' '
>  	test_must_fail git tag -v forged-tag
>  '
>  
> +test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
> +	cat >expect <<-\EOF 

Trailing whitespace after "EOF" here (and below). Otherwise the tests
look reasonable to me.

-Peff

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

* Re: [PATCH v5 0/7] Add --format to tag verification
  2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
                   ` (6 preceding siblings ...)
  2017-01-15 18:47 ` [PATCH v5 7/7] t/t7004-tag: " santiago
@ 2017-01-17 15:36 ` Jeff King
  7 siblings, 0 replies; 21+ messages in thread
From: Jeff King @ 2017-01-17 15:36 UTC (permalink / raw)
  To: santiago; +Cc: git, gitster, sunshine, walters

On Sun, Jan 15, 2017 at 01:46:58PM -0500, santiago@nyu.edu wrote:

> From: Santiago Torres <santiago@nyu.edu>
> 
> This is the fifth iteration of [1][2][3][4], and as a result of the
> discussion in [5]. The main goal of this patch series is to bring
> --format to git tag verification so that upper-layer tools can inspect
> the content of a tag and make decisions based on it.

Thanks for picking this back up.  I didn't see any bugs, but I had a few
interface nits, which I sent inline.

-Peff

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 15:30     ` Jeff King
@ 2017-01-17 16:57       ` Santiago Torres
  2017-01-17 17:25         ` Jeff King
  0 siblings, 1 reply; 21+ messages in thread
From: Santiago Torres @ 2017-01-17 16:57 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

> > Hrm. Maybe I am missing something, but what does:
> > 
> >   verify_and_format_tag(sha1, name, fmt, flags);
> > 
> > get you over:
> > 
> >   gpg_verify_tag(sha1, name, flags);
> >   pretty_print_ref(name, sha1, fmt);
> > 
> > ? The latter seems much more flexible, and I do not see how the
> > verification step impacts the printing at all (or vice versa).
> > 
> > I could understand it more if there were patches later in the series
> > that somehow used the format and verification results together. But I
> > didn't see that.
> 
> Having read through the rest of the series, it looks like you'd
> sometimes have to do:

IIRC, we did this to make the diff "simpler". It also feeds odd that the
call chain is the following:

    verify_and_format_tag()
    gpg_verify_tag()
    run_gpg_verification()

I'm afraid that adding yet another wrapper would further convolute the
call chain. If you think this is not an issue, I could easily do it. Do
you have any suggested name for the wrapper?

Thanks!
-Santiago

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v5 5/7] builtin/tag: add --format argument for tag -v
  2017-01-17 15:34   ` Jeff King
@ 2017-01-17 17:00     ` Santiago Torres
  2017-01-17 17:32       ` Jeff King
  0 siblings, 1 reply; 21+ messages in thread
From: Santiago Torres @ 2017-01-17 17:00 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

> >  {
> > -	return verify_and_format_tag(sha1, name, NULL, GPG_VERIFY_VERBOSE);
> > +	int flags;
> > +	char *fmt_pretty = cb_data;
> > +	flags = GPG_VERIFY_VERBOSE;
> > +
> > +	if (fmt_pretty)
> > +		flags = GPG_VERIFY_QUIET;
> > +
> > +	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
> 
> It seems funny that VERBOSE and QUIET are bit-flags. What happens when
> you ask for GPG_VERIFY_VERBOSE|GPG_VERIFY_QUIET?

If I'm not mistaken, the way the code works right now this is not
possible (GPG_VERIFY_VERBOSE will be unset when GPG_VERIFY_QUIET). I
would have to re-read the patch to make sure this is the case then.

GPG_VERIFY_QUIET was added to suppress any VERBOSE|RAW flags, we could
defeault to QUIET if flags are not set. What do you think?

Thanks!
-Santiago

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 16:57       ` Santiago Torres
@ 2017-01-17 17:25         ` Jeff King
  2017-01-17 17:30           ` Jeff King
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 17:25 UTC (permalink / raw)
  To: Santiago Torres; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Tue, Jan 17, 2017 at 11:57:25AM -0500, Santiago Torres wrote:

> > Having read through the rest of the series, it looks like you'd
> > sometimes have to do:
> 
> IIRC, we did this to make the diff "simpler". It also feeds odd that the
> call chain is the following:
> 
>     verify_and_format_tag()
>     gpg_verify_tag()
>     run_gpg_verification()
> 
> I'm afraid that adding yet another wrapper would further convolute the
> call chain. If you think this is not an issue, I could easily do it. Do
> you have any suggested name for the wrapper?

Actually, looking at the callsites, I think they are fine to just call
pretty_print_ref() themselves, and I don't think it actually matters if
it happens before or after the verification.

So I think you could just throw out patch 3 entirely and squash these
hunks into patches 4 and 5:

diff --git a/builtin/tag.c b/builtin/tag.c
index 9da11e0c2..fab9fa8f9 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -111,10 +111,12 @@ static int verify_tag(const char *name, const char *ref,
 	char *fmt_pretty = cb_data;
 	flags = GPG_VERIFY_VERBOSE;
 
-	if (fmt_pretty)
+	if (fmt_pretty) {
 		flags = GPG_VERIFY_QUIET;
+		pretty_print_ref(name, sha1, fmt_pretty);
+	}
 
-	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
+	return gpg_verify_tag(sha1, ref, flags);
 }
 
 static int do_sign(struct strbuf *buffer)
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 212449f47..114df1c52 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -58,9 +58,15 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	while (i < argc) {
 		unsigned char sha1[20];
 		const char *name = argv[i++];
-		if (get_sha1(name, sha1))
+
+		if (get_sha1(name, sha1)) {
 			had_error = !!error("tag '%s' not found.", name);
-		else if (verify_and_format_tag(sha1, name, fmt_pretty, flags))
+			continue;
+		}
+
+		if (fmt_pretty)
+			pretty_print_ref(name, sha1, fmt_pretty);
+		if (gpg_verify_tag(sha1, name, flags))
 			had_error = 1;
 	}
 	return had_error;

You could make the diff in the second one simpler by skipping the
"continue" and just doing the whole thing in an "else" block. But IMHO
the continue-on-error makes the logic more clear.

-Peff

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 17:25         ` Jeff King
@ 2017-01-17 17:30           ` Jeff King
  2017-01-17 17:33             ` Santiago Torres
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 17:30 UTC (permalink / raw)
  To: Santiago Torres; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Tue, Jan 17, 2017 at 12:25:31PM -0500, Jeff King wrote:

> Actually, looking at the callsites, I think they are fine to just call
> pretty_print_ref() themselves, and I don't think it actually matters if
> it happens before or after the verification.

Oh, sorry, I misread it. We do indeed early-return from the verification
and skip the printing in that case. So it'd be more like:

diff --git a/builtin/tag.c b/builtin/tag.c
index 9da11e0c2..068f392b6 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -114,7 +114,11 @@ static int verify_tag(const char *name, const char *ref,
 	if (fmt_pretty)
 		flags = GPG_VERIFY_QUIET;
 
-	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
+	if (gpg_verify_tag(sha1, ref, flags))
+		return -1;
+
+	pretty_print_ref(name, sha1, fmt_pretty);
+	return 0;
 }
 
 static int do_sign(struct strbuf *buffer)
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 212449f47..b3f08f705 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -58,10 +58,19 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	while (i < argc) {
 		unsigned char sha1[20];
 		const char *name = argv[i++];
-		if (get_sha1(name, sha1))
+
+		if (get_sha1(name, sha1)) {
 			had_error = !!error("tag '%s' not found.", name);
-		else if (verify_and_format_tag(sha1, name, fmt_pretty, flags))
+			continue;
+		}
+
+		if (gpg_verify_tag(sha1, name, flags)) {
 			had_error = 1;
+			continue;
+		}
+
+		if (fmt_pretty)
+			pretty_print_ref(name, sha1, fmt_pretty);
 	}
 	return had_error;
 }

which I think is still an improvement (the printing, rather than being
an obscure parameter to the overloaded verify_and_format_tag()
function, is clearly a first-class operation).

-Peff

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

* Re: [PATCH v5 5/7] builtin/tag: add --format argument for tag -v
  2017-01-17 17:00     ` Santiago Torres
@ 2017-01-17 17:32       ` Jeff King
  2017-01-17 17:34         ` Santiago Torres
  0 siblings, 1 reply; 21+ messages in thread
From: Jeff King @ 2017-01-17 17:32 UTC (permalink / raw)
  To: Santiago Torres; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Tue, Jan 17, 2017 at 12:00:19PM -0500, Santiago Torres wrote:

> > >  {
> > > -	return verify_and_format_tag(sha1, name, NULL, GPG_VERIFY_VERBOSE);
> > > +	int flags;
> > > +	char *fmt_pretty = cb_data;
> > > +	flags = GPG_VERIFY_VERBOSE;
> > > +
> > > +	if (fmt_pretty)
> > > +		flags = GPG_VERIFY_QUIET;
> > > +
> > > +	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
> > 
> > It seems funny that VERBOSE and QUIET are bit-flags. What happens when
> > you ask for GPG_VERIFY_VERBOSE|GPG_VERIFY_QUIET?
> 
> If I'm not mistaken, the way the code works right now this is not
> possible (GPG_VERIFY_VERBOSE will be unset when GPG_VERIFY_QUIET). I
> would have to re-read the patch to make sure this is the case then.

No, you're right that the two flags are mutually exclusive in the
current callers. So I don't think there's a bug here. It's just that the
interface is potentially awkward/confusing, which may be a problem down
the line.

VERBOSE|QUIET _does_ have a meaning, which is "show the payload, but do
not print the signature buffer". Perhaps just renaming QUIET to
OMIT_STATUS or something would make it more clear.

-Peff

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 17:30           ` Jeff King
@ 2017-01-17 17:33             ` Santiago Torres
  2017-01-17 17:34               ` Jeff King
  0 siblings, 1 reply; 21+ messages in thread
From: Santiago Torres @ 2017-01-17 17:33 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

[-- Attachment #1: Type: text/plain, Size: 2059 bytes --]

Yeah, this actually looks more cleaner.

Let me give it a go.

Thanks!
-Santiago.

On Tue, Jan 17, 2017 at 12:30:04PM -0500, Jeff King wrote:
> On Tue, Jan 17, 2017 at 12:25:31PM -0500, Jeff King wrote:
> 
> > Actually, looking at the callsites, I think they are fine to just call
> > pretty_print_ref() themselves, and I don't think it actually matters if
> > it happens before or after the verification.
> 
> Oh, sorry, I misread it. We do indeed early-return from the verification
> and skip the printing in that case. So it'd be more like:
> 
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 9da11e0c2..068f392b6 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -114,7 +114,11 @@ static int verify_tag(const char *name, const char *ref,
>  	if (fmt_pretty)
>  		flags = GPG_VERIFY_QUIET;
>  
> -	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
> +	if (gpg_verify_tag(sha1, ref, flags))
> +		return -1;
> +
> +	pretty_print_ref(name, sha1, fmt_pretty);
> +	return 0;
>  }
>  
>  static int do_sign(struct strbuf *buffer)
> diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
> index 212449f47..b3f08f705 100644
> --- a/builtin/verify-tag.c
> +++ b/builtin/verify-tag.c
> @@ -58,10 +58,19 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
>  	while (i < argc) {
>  		unsigned char sha1[20];
>  		const char *name = argv[i++];
> -		if (get_sha1(name, sha1))
> +
> +		if (get_sha1(name, sha1)) {
>  			had_error = !!error("tag '%s' not found.", name);
> -		else if (verify_and_format_tag(sha1, name, fmt_pretty, flags))
> +			continue;
> +		}
> +
> +		if (gpg_verify_tag(sha1, name, flags)) {
>  			had_error = 1;
> +			continue;
> +		}
> +
> +		if (fmt_pretty)
> +			pretty_print_ref(name, sha1, fmt_pretty);
>  	}
>  	return had_error;
>  }
> 
> which I think is still an improvement (the printing, rather than being
> an obscure parameter to the overloaded verify_and_format_tag()
> function, is clearly a first-class operation).
> 
> -Peff

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v5 5/7] builtin/tag: add --format argument for tag -v
  2017-01-17 17:32       ` Jeff King
@ 2017-01-17 17:34         ` Santiago Torres
  0 siblings, 0 replies; 21+ messages in thread
From: Santiago Torres @ 2017-01-17 17:34 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

> VERBOSE|QUIET _does_ have a meaning, which is "show the payload, but do
> not print the signature buffer". Perhaps just renaming QUIET to
> OMIT_STATUS or something would make it more clear.
> 
Let me give this a go too. OMIT_STATUS does sound less confusing.

Thanks,
-Santiago.

> -Peff

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag
  2017-01-17 17:33             ` Santiago Torres
@ 2017-01-17 17:34               ` Jeff King
  0 siblings, 0 replies; 21+ messages in thread
From: Jeff King @ 2017-01-17 17:34 UTC (permalink / raw)
  To: Santiago Torres; +Cc: git, gitster, sunshine, walters, Lukas Puehringer

On Tue, Jan 17, 2017 at 12:33:46PM -0500, Santiago Torres wrote:

> Yeah, this actually looks more cleaner.
> 
> Let me give it a go.

Neat. Note there's a bug:

> > diff --git a/builtin/tag.c b/builtin/tag.c
> > index 9da11e0c2..068f392b6 100644
> > --- a/builtin/tag.c
> > +++ b/builtin/tag.c
> > @@ -114,7 +114,11 @@ static int verify_tag(const char *name, const char *ref,
> >  	if (fmt_pretty)
> >  		flags = GPG_VERIFY_QUIET;
> >  
> > -	return verify_and_format_tag(sha1, ref, fmt_pretty, flags);
> > +	if (gpg_verify_tag(sha1, ref, flags))
> > +		return -1;
> > +
> > +	pretty_print_ref(name, sha1, fmt_pretty);
> > +	return 0;

The final print should be guarded by "if (fmt_pretty)".

-Peff

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

end of thread, other threads:[~2017-01-17 17:43 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-15 18:46 [PATCH v5 0/7] Add --format to tag verification santiago
2017-01-15 18:46 ` [PATCH v5 1/7] gpg-interface, tag: add GPG_VERIFY_QUIET flag santiago
2017-01-15 18:47 ` [PATCH v5 2/7] ref-filter: add function to print single ref_array_item santiago
2017-01-15 18:47 ` [PATCH v5 3/7] tag: add format specifier to gpg_verify_tag santiago
2017-01-17 15:24   ` Jeff King
2017-01-17 15:30     ` Jeff King
2017-01-17 16:57       ` Santiago Torres
2017-01-17 17:25         ` Jeff King
2017-01-17 17:30           ` Jeff King
2017-01-17 17:33             ` Santiago Torres
2017-01-17 17:34               ` Jeff King
2017-01-15 18:47 ` [PATCH v5 4/7] builtin/verify-tag: add --format to verify-tag santiago
2017-01-15 18:47 ` [PATCH v5 5/7] builtin/tag: add --format argument for tag -v santiago
2017-01-17 15:34   ` Jeff King
2017-01-17 17:00     ` Santiago Torres
2017-01-17 17:32       ` Jeff King
2017-01-17 17:34         ` Santiago Torres
2017-01-15 18:47 ` [PATCH v5 6/7] t/t7030-verify-tag: Add --format specifier tests santiago
2017-01-15 18:47 ` [PATCH v5 7/7] t/t7004-tag: " santiago
2017-01-17 15:35   ` Jeff King
2017-01-17 15:36 ` [PATCH v5 0/7] Add --format to tag verification Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).