Skip to content

Commit ea5517f

Browse files
peffgitster
authored andcommitted
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>
1 parent 6876618 commit ea5517f

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

commit.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -584,25 +584,19 @@ define_commit_slab(author_date_slab, unsigned long);
584584
static void record_author_date(struct author_date_slab *author_date,
585585
struct commit *commit)
586586
{
587-
const char *buf, *line_end, *ident_line;
588587
const char *buffer = get_commit_buffer(commit, NULL);
589588
struct ident_split ident;
589+
const char *ident_line;
590+
size_t ident_len;
590591
char *date_end;
591592
unsigned long date;
592593

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 */
606600

607601
date = strtoul(ident.date_begin, &date_end, 10);
608602
if (date_end != ident.date_end)

0 commit comments

Comments
 (0)