Skip to content

Commit c9ad147

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b358476 commit c9ad147

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fsck.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
FUNC(MISSING_TREE, ERROR) \
3939
FUNC(MISSING_TYPE, ERROR) \
4040
FUNC(MISSING_TYPE_ENTRY, ERROR) \
41+
FUNC(MULTIPLE_AUTHORS, ERROR) \
4142
FUNC(NUL_IN_HEADER, ERROR) \
4243
FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
4344
FUNC(TREE_NOT_SORTED, ERROR) \
@@ -529,7 +530,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
529530
{
530531
unsigned char tree_sha1[20], sha1[20];
531532
struct commit_graft *graft;
532-
unsigned parent_count, parent_line_count = 0;
533+
unsigned parent_count, parent_line_count = 0, author_count;
533534
int err;
534535

535536
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,
569570
return err;
570571
}
571572
}
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");
575584
if (err)
576585
return err;
577586
if (!skip_prefix(buffer, "committer ", &buffer))

0 commit comments

Comments
 (0)