summaryrefslogtreecommitdiff
path: root/gpg-interface.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-04-13 21:18:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-04-16 05:15:03 (GMT)
commitf68f2dd57f55e0b1782b20b615dd7a96d7fb6a41 (patch)
treef7b761c06a9cb5a13e45069b43b0712ebc63371c /gpg-interface.c
parent17ef3a421e0a1019592a0b14b95f09df61730071 (diff)
downloadgit-f68f2dd57f55e0b1782b20b615dd7a96d7fb6a41.zip
git-f68f2dd57f55e0b1782b20b615dd7a96d7fb6a41.tar.gz
git-f68f2dd57f55e0b1782b20b615dd7a96d7fb6a41.tar.bz2
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>
Diffstat (limited to 'gpg-interface.c')
-rw-r--r--gpg-interface.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/gpg-interface.c b/gpg-interface.c
index 3414af3..79333c1 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -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;
}