fsck: handle multiple authors in commits specially

This problem has been detected in the wild, and is the primary reason to introduce an option to demote certain fsck errors to warnings. Let's offer to ignore this particular problem specifically. Technically, we could handle such repositories by setting receive.fsck.<msg-id> to missingCommitter=warn, but that could hide missing tree objects in the same commit because we cannot continue verifying any commit object after encountering a missing committer line, while we can continue in the case of multiple author lines. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 22, 2015 at 17:26 UTC c9ad147f83f70b6add9066e16e1e44c8bc3d5c13
1 file changed +13 -4
fsck.c
+13 -4
@@ -38,6 +38,7 @@
38 FUNC(MISSING_TREE, ERROR) \
39 FUNC(MISSING_TYPE, ERROR) \
40 FUNC(MISSING_TYPE_ENTRY, ERROR) \
41 + FUNC(MULTIPLE_AUTHORS, ERROR) \
42 FUNC(NUL_IN_HEADER, ERROR) \
43 FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
44 FUNC(TREE_NOT_SORTED, ERROR) \
@@ -529,7 +530,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
530 {
531 unsigned char tree_sha1[20], sha1[20];
532 struct commit_graft *graft;
532 - unsigned parent_count, parent_line_count = 0;
533 + unsigned parent_count, parent_line_count = 0, author_count;
534 int err;
535
536 if (require_end_of_header(buffer, size, &commit->object, options))
@@ -569,9 +570,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
570 return err;
571 }
572 }
572 - if (!skip_prefix(buffer, "author ", &buffer))
573 - return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
574 - err = fsck_ident(&buffer, &commit->object, options);
573 + author_count = 0;
574 + while (skip_prefix(buffer, "author ", &buffer)) {
575 + author_count++;
576 + err = fsck_ident(&buffer, &commit->object, options);
577 + if (err)
578 + return err;
579 + }
580 + if (author_count < 1)
581 + err = report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
582 + else if (author_count > 1)
583 + err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
584 if (err)
585 return err;
586 if (!skip_prefix(buffer, "committer ", &buffer))