record_author_date(): use find_commit_header()

This saves us some manual parsing and makes the code more readable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 27, 2014 at 03:56 UTC ea5517f04b08bdb40eca72888220bd6a90d3cf17
1 file changed +8 -14
commit.c
+8 -14
@@ -584,25 +584,19 @@ define_commit_slab(author_date_slab, unsigned long);
584 static void record_author_date(struct author_date_slab *author_date,
585 struct commit *commit)
586 {
587 - const char *buf, *line_end, *ident_line;
587 const char *buffer = get_commit_buffer(commit, NULL);
588 struct ident_split ident;
589 + const char *ident_line;
590 + size_t ident_len;
591 char *date_end;
592 unsigned long date;
593
593 - for (buf = buffer; buf; buf = line_end + 1) {
594 - line_end = strchrnul(buf, '\n');
595 - if (!skip_prefix(buf, "author ", &ident_line)) {
596 - if (!line_end[0] || line_end[1] == '\n')
597 - goto fail_exit; /* end of header */
598 - continue;
599 - }
600 - if (split_ident_line(&ident,
601 - ident_line, line_end - ident_line) ||
602 - !ident.date_begin || !ident.date_end)
603 - goto fail_exit; /* malformed "author" line */
604 - break;
605 - }
594 + ident_line = find_commit_header(buffer, "author", &ident_len);
595 + if (!ident_line)
596 + goto fail_exit; /* no author line */
597 + if (split_ident_line(&ident, ident_line, ident_len) ||
598 + !ident.date_begin || !ident.date_end)
599 + goto fail_exit; /* malformed "author" line */
600
601 date = strtoul(ident.date_begin, &date_end, 10);
602 if (date_end != ident.date_end)