gpg-interface: extract gpg line matching helper

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>

Jeff King committed Apr 13, 2018 at 15:18 UTC f68f2dd57f55e0b1782b20b615dd7a96d7fb6a41
1 file changed +7 -2
gpg-interface.c
+7 -2
@@ -101,11 +101,16 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
101 fputs(output, stderr);
102 }
103
104 +static int is_gpg_start(const char *line)
105 +{
106 + return starts_with(line, PGP_SIGNATURE) ||
107 + starts_with(line, PGP_MESSAGE);
108 +}
109 +
110 size_t parse_signature(const char *buf, size_t size)
111 {
112 size_t len = 0;
107 - while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
108 - !starts_with(buf + len, PGP_MESSAGE)) {
113 + while (len < size && !is_gpg_start(buf + len)) {
114 const char *eol = memchr(buf + len, '\n', size - len);
115 len += eol ? eol - (buf + len) + 1 : size - len;
116 }