commit.c: use skip_prefix() instead of starts_with()

In record_author_date() & parse_gpg_output(), the callers of starts_with() not just want to know if the string starts with the prefix, but also can benefit from knowing the string that follows the prefix. By using skip_prefix(), we can do both at the same time. Helped-by: Max Horn <max@quendi.de> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Mar 4, 2014 at 13:06 UTC 147972b1a67425aefb949630d3b97d547f561654
1 file changed +6 -8
commit.c
+6 -8
@@ -548,7 +548,7 @@ define_commit_slab(author_date_slab, unsigned long);
548 static void record_author_date(struct author_date_slab *author_date,
549 struct commit *commit)
550 {
551 - const char *buf, *line_end;
551 + const char *buf, *line_end, *ident_line;
552 char *buffer = NULL;
553 struct ident_split ident;
554 char *date_end;
@@ -566,14 +566,14 @@ static void record_author_date(struct author_date_slab *author_date,
566 buf;
567 buf = line_end + 1) {
568 line_end = strchrnul(buf, '\n');
569 - if (!starts_with(buf, "author ")) {
569 + ident_line = skip_prefix(buf, "author ");
570 + if (!ident_line) {
571 if (!line_end[0] || line_end[1] == '\n')
572 return; /* end of header */
573 continue;
574 }
575 if (split_ident_line(&ident,
575 - buf + strlen("author "),
576 - line_end - (buf + strlen("author "))) ||
576 + ident_line, line_end - ident_line) ||
577 !ident.date_begin || !ident.date_end)
578 goto fail_exit; /* malformed "author" line */
579 break;
@@ -1193,10 +1193,8 @@ static void parse_gpg_output(struct signature_check *sigc)
1193 for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
1194 const char *found, *next;
1195
1196 - if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
1197 - /* At the very beginning of the buffer */
1198 - found = buf + strlen(sigcheck_gpg_status[i].check + 1);
1199 - } else {
1196 + found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
1197 + if (!found) {
1198 found = strstr(buf, sigcheck_gpg_status[i].check);
1199 if (!found)
1200 continue;