[PATCH 5/5] verify_tag_signature(): let caller look up tag object sha1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Avoid an unnecessary get_sha1() call in cmd_tag().

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 builtin/tag.c        |    2 +-
 builtin/verify-tag.c |   16 ++++++++++++++--
 tag.h                |    3 ++-
 verify-tag.c         |    6 +-----
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index d138e0c..df94a8c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -147,7 +147,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)
 {
-	if (verify_tag_signature(sha1_to_hex(sha1), 1))
+	if (verify_tag_signature(sha1, name, 1))
 		return error("could not verify the tag '%s'", name);
 	return 0;
 }
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index ca075bd..df2e095 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -14,6 +14,13 @@ static const char * const verify_tag_usage[] = {
 		NULL
 };
 
+static int get_sha1_or_whine(const char *name, unsigned char *sha1)
+{
+	if (get_sha1(name, sha1))
+		return error("tag '%s' not found.", name);
+	return 0;
+}
+
 int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 {
 	int i = 1, verbose = 0, had_error = 0;
@@ -29,8 +36,13 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	if (argc <= i)
 		usage_with_options(verify_tag_usage, verify_tag_options);
 
-	while (i < argc)
-		if (verify_tag_signature(argv[i++], verbose))
+	while (i < argc) {
+		unsigned char sha1[20];
+		const char *name = argv[i++];
+
+		if (get_sha1_or_whine(name, sha1) < 0 ||
+		    verify_tag_signature(sha1, name, verbose) < 0)
 			had_error = 1;
+	}
 	return had_error;
 }
diff --git a/tag.h b/tag.h
index 1034109..f83dce6 100644
--- a/tag.h
+++ b/tag.h
@@ -16,6 +16,7 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
 extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
 extern int parse_tag(struct tag *item);
 extern struct object *deref_tag(struct object *, const char *, int);
-extern int verify_tag_signature(const char *name, int verbose);
+extern int verify_tag_signature(const unsigned char *sha1, const char *name,
+				int verbose);
 
 #endif /* TAG_H */
diff --git a/verify-tag.c b/verify-tag.c
index 7152e99..bf88707 100644
--- a/verify-tag.c
+++ b/verify-tag.c
@@ -60,17 +60,13 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
 	return ret;
 }
 
-int verify_tag_signature(const char *name, int verbose)
+int verify_tag_signature(const unsigned char *sha1, const char *name, int verbose)
 {
 	enum object_type type;
-	unsigned char sha1[20];
 	char *buf;
 	unsigned long size;
 	int ret;
 
-	if (get_sha1(name, sha1))
-		return error("tag '%s' not found.", name);
-
 	type = sha1_object_info(sha1, NULL);
 	if (type != OBJ_TAG)
 		return error("%s: cannot verify a non-tag object of type %s.",
-- 
1.7.0.2

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]