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>
This commit is contained in:
Johannes Schindelin 2015-06-22 17:26:23 +02:00 коммит произвёл Junio C Hamano
Родитель b3584761eb
Коммит c9ad147f83
1 изменённых файлов: 13 добавлений и 4 удалений

15
fsck.c
Просмотреть файл

@ -38,6 +38,7 @@
FUNC(MISSING_TREE, ERROR) \ FUNC(MISSING_TREE, ERROR) \
FUNC(MISSING_TYPE, ERROR) \ FUNC(MISSING_TYPE, ERROR) \
FUNC(MISSING_TYPE_ENTRY, ERROR) \ FUNC(MISSING_TYPE_ENTRY, ERROR) \
FUNC(MULTIPLE_AUTHORS, ERROR) \
FUNC(NUL_IN_HEADER, ERROR) \ FUNC(NUL_IN_HEADER, ERROR) \
FUNC(TAG_OBJECT_NOT_TAG, ERROR) \ FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
FUNC(TREE_NOT_SORTED, ERROR) \ FUNC(TREE_NOT_SORTED, ERROR) \
@ -529,7 +530,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
{ {
unsigned char tree_sha1[20], sha1[20]; unsigned char tree_sha1[20], sha1[20];
struct commit_graft *graft; struct commit_graft *graft;
unsigned parent_count, parent_line_count = 0; unsigned parent_count, parent_line_count = 0, author_count;
int err; int err;
if (require_end_of_header(buffer, size, &commit->object, options)) if (require_end_of_header(buffer, size, &commit->object, options))
@ -569,11 +570,19 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
return err; return err;
} }
} }
if (!skip_prefix(buffer, "author ", &buffer)) author_count = 0;
return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line"); while (skip_prefix(buffer, "author ", &buffer)) {
author_count++;
err = fsck_ident(&buffer, &commit->object, options); err = fsck_ident(&buffer, &commit->object, options);
if (err) if (err)
return err; return err;
}
if (author_count < 1)
err = report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
else if (author_count > 1)
err = report(options, &commit->object, FSCK_MSG_MULTIPLE_AUTHORS, "invalid format - multiple 'author' lines");
if (err)
return err;
if (!skip_prefix(buffer, "committer ", &buffer)) if (!skip_prefix(buffer, "committer ", &buffer))
return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line"); return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
err = fsck_ident(&buffer, &commit->object, options); err = fsck_ident(&buffer, &commit->object, options);