gpg-interface: extract gpg line matching helper
authorJeff King <peff@peff.net>
Fri, 13 Apr 2018 21:18:34 +0000 (15:18 -0600)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Apr 2018 05:15:03 +0000 (14:15 +0900)
Let's separate the actual line-by-line parsing of signatures
from the notion of "is this a gpg signature line". That will
make it easier to do more refactoring of this loop in future
patches.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Ben Toews <mastahyeti@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gpg-interface.c
index 3414af38b9d1b7ff8be0f3d24e9086a1059b1717..79333c1ee8a6a1454cc7989186297e9412086ac5 100644 (file)
@@ -101,11 +101,16 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
                fputs(output, stderr);
 }
 
+static int is_gpg_start(const char *line)
+{
+       return starts_with(line, PGP_SIGNATURE) ||
+               starts_with(line, PGP_MESSAGE);
+}
+
 size_t parse_signature(const char *buf, size_t size)
 {
        size_t len = 0;
-       while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
-                       !starts_with(buf + len, PGP_MESSAGE)) {
+       while (len < size && !is_gpg_start(buf + len)) {
                const char *eol = memchr(buf + len, '\n', size - len);
                len += eol ? eol - (buf + len) + 1 : size - len;
        }