@matheusbsbs / matheus-bagliano / commits / ac58c4c795
Fork 0

verify-tag: factor out signature detection

into tag.h/c for later reuse and modification. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Nov 10, 2010 at 12:17 UTC ac58c4c795455addd0d8f007e969d56e43f1165b
3 files changed +16 -8
builtin/verify-tag.c
+2 -8
@@ -17,13 +17,11 @@ static const char * const verify_tag_usage[] = {
17 NULL
18 };
19
20 -#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
21 -
20 static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
21 {
22 struct child_process gpg;
23 const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL};
26 - char path[PATH_MAX], *eol;
24 + char path[PATH_MAX];
25 size_t len;
26 int fd, ret;
27
@@ -37,11 +35,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
35 close(fd);
36
37 /* find the length without signature */
40 - len = 0;
41 - while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
42 - eol = memchr(buf + len, '\n', size - len);
43 - len += eol ? eol - (buf + len) + 1 : size - len;
44 - }
38 + len = parse_signature(buf, size);
39 if (verbose)
40 write_in_full(1, buf, len);
41
tag.c
+13
@@ -4,6 +4,8 @@
4 #include "tree.h"
5 #include "blob.h"
6
7 +#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
8 +
9 const char *tag_type = "tag";
10
11 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
@@ -133,3 +135,14 @@ int parse_tag(struct tag *item)
135 free(data);
136 return ret;
137 }
138 +
139 +size_t parse_signature(const char *buf, unsigned long size)
140 +{
141 + char *eol;
142 + size_t len = 0;
143 + while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) {
144 + eol = memchr(buf + len, '\n', size - len);
145 + len += eol ? eol - (buf + len) + 1 : size - len;
146 + }
147 + return len;
148 +}
tag.h
+1
@@ -16,5 +16,6 @@ extern struct tag *lookup_tag(const unsigned char *sha1);
16 extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
17 extern int parse_tag(struct tag *item);
18 extern struct object *deref_tag(struct object *, const char *, int);
19 +extern size_t parse_signature(const char *buf, unsigned long size);
20
21 #endif /* TAG_H */