verify-tag: prepare verify_tag for libification
The current interface of verify_tag() resolves reference names to SHA1, however, the plan is to make this functionality public and the current interface is cumbersome for callers: they are expected to supply the textual representation of a sha1/refname. In many cases, this requires them to turn the sha1 to hex representation, just to be converted back inside verify_tag. Add a SHA1 parameter to use instead of the name parameter, and rename the name parameter to "name_to_report" for reporting purposes only. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Santiago Torres <santiago@nyu.edu> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Santiago Torres committed
Apr 19, 2016 at 13:47 UTC
78ccd4419525562a2c9d2b7cebddba0914bde151
1 file changed
+17
-9
builtin/verify-tag.c
+17
-9
@@ -42,25 +42,28 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
42
return ret;
43
}
44
45
-static int verify_tag(const char *name, unsigned flags)
45
+static int verify_tag(const unsigned char *sha1, const char *name_to_report,
46
+ unsigned flags)
47
{
48
enum object_type type;
48
- unsigned char sha1[20];
49
char *buf;
50
unsigned long size;
51
int ret;
52
53
- if (get_sha1(name, sha1))
54
- return error("tag '%s' not found.", name);
55
-
53
type = sha1_object_info(sha1, NULL);
54
if (type != OBJ_TAG)
55
return error("%s: cannot verify a non-tag object of type %s.",
59
- name, typename(type));
56
+ name_to_report ?
57
+ name_to_report :
58
+ find_unique_abbrev(sha1, DEFAULT_ABBREV),
59
+ typename(type));
60
61
buf = read_sha1_file(sha1, &type, &size);
62
if (!buf)
63
- return error("%s: unable to read file.", name);
63
+ return error("%s: unable to read file.",
64
+ name_to_report ?
65
+ name_to_report :
66
+ find_unique_abbrev(sha1, DEFAULT_ABBREV));
67
68
ret = run_gpg_verify(buf, size, flags);
69
@@ -96,8 +99,13 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
99
if (verbose)
100
flags |= GPG_VERIFY_VERBOSE;
101
99
- while (i < argc)
100
- if (verify_tag(argv[i++], flags))
102
+ while (i < argc) {
103
+ unsigned char sha1[20];
104
+ const char *name = argv[i++];
105
+ if (get_sha1(name, sha1))
106
+ had_error = !!error("tag '%s' not found.", name);
107
+ else if (verify_tag(sha1, name, flags))
108
had_error = 1;
109
+ }
110
return had_error;
111
}