From ac58c4c795455addd0d8f007e969d56e43f1165b Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 10 Nov 2010 12:17:27 +0100 Subject: verify-tag: factor out signature detection into tag.h/c for later reuse and modification. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/verify-tag.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'builtin') diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 9f482c29f..86cac6d71 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -17,13 +17,11 @@ static const char * const verify_tag_usage[] = { NULL }; -#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----" - static int run_gpg_verify(const char *buf, unsigned long size, int verbose) { struct child_process gpg; const char *args_gpg[] = {"gpg", "--verify", "FILE", "-", NULL}; - char path[PATH_MAX], *eol; + char path[PATH_MAX]; size_t len; int fd, ret; @@ -37,11 +35,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose) close(fd); /* find the length without signature */ - len = 0; - while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) { - eol = memchr(buf + len, '\n', size - len); - len += eol ? eol - (buf + len) + 1 : size - len; - } + len = parse_signature(buf, size); if (verbose) write_in_full(1, buf, len); -- cgit v1.2.1 From e10dfb62ee21a3970ccfe44f30f97fcd6457bb78 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 10 Nov 2010 12:17:28 +0100 Subject: tag: factor out sig detection for body edits Use the factored out code for sig detection when editing existing tag bodies (tag -a -f without -m). Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/tag.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'builtin') diff --git a/builtin/tag.c b/builtin/tag.c index d311491e4..66feeb0c6 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -29,8 +29,6 @@ struct tag_filter { struct commit_list *with_commit; }; -#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----" - static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { @@ -242,8 +240,7 @@ static void write_tag_body(int fd, const unsigned char *sha1) { unsigned long size; enum object_type type; - char *buf, *sp, *eob; - size_t len; + char *buf, *sp; buf = read_sha1_file(sha1, &type, &size); if (!buf) @@ -256,12 +253,7 @@ static void write_tag_body(int fd, const unsigned char *sha1) return; } sp += 2; /* skip the 2 LFs */ - eob = strstr(sp, "\n" PGP_SIGNATURE "\n"); - if (eob) - len = eob - sp; - else - len = buf + size - sp; - write_or_die(fd, sp, len); + write_or_die(fd, sp, parse_signature(sp, buf + size - sp)); free(buf); } -- cgit v1.2.1 From 81536b2dfae5a2839b6f20b22cc814a3690e4704 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 10 Nov 2010 12:17:29 +0100 Subject: tag: factor out sig detection for tag display Use the factored out code for sig detection when displaying tags. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/tag.c b/builtin/tag.c index 66feeb0c6..617a58f05 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -68,9 +68,9 @@ static int show_reference(const char *refname, const unsigned char *sha1, return 0; } /* only take up to "lines" lines, and strip the signature */ + size = parse_signature(buf, size); for (i = 0, sp += 2; - i < filter->lines && sp < buf + size && - prefixcmp(sp, PGP_SIGNATURE "\n"); + i < filter->lines && sp < buf + size; i++) { if (i) printf("\n "); -- cgit v1.2.1