fsck: make fsck_commit() warn-friendly
When fsck_commit() identifies a problem with the commit, it should try to make it possible to continue checking the commit object, in case the user wants to demote the detected errors to mere warnings. Note that some problems are too problematic to simply ignore. For example, when the header lines are mixed up, we punt after encountering an incorrect line. Therefore, demoting certain warnings to errors can hide other problems. Example: demoting the missingauthor error to a warning would hide a problematic committer line. 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
b3584761eb7284263e702088d71cc6f094fbb926
1 file changed
+20
-8
fsck.c
+20
-8
@@ -537,12 +537,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
537
538
if (!skip_prefix(buffer, "tree ", &buffer))
539
return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
540
- if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
541
- return report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
540
+ if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n') {
541
+ err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
542
+ if (err)
543
+ return err;
544
+ }
545
buffer += 41;
546
while (skip_prefix(buffer, "parent ", &buffer)) {
544
- if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
545
- return report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
547
+ if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
548
+ err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
549
+ if (err)
550
+ return err;
551
+ }
552
buffer += 41;
553
parent_line_count++;
554
}
@@ -551,11 +557,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
557
if (graft) {
558
if (graft->nr_parent == -1 && !parent_count)
559
; /* shallow commit */
554
- else if (graft->nr_parent != parent_count)
555
- return report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
560
+ else if (graft->nr_parent != parent_count) {
561
+ err = report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
562
+ if (err)
563
+ return err;
564
+ }
565
} else {
557
- if (parent_count != parent_line_count)
558
- return report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
566
+ if (parent_count != parent_line_count) {
567
+ err = report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
568
+ if (err)
569
+ return err;
570
+ }
571
}
572
if (!skip_prefix(buffer, "author ", &buffer))
573
return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");