fsck: make fsck_commit() warn-friendly
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 22 Jun 2015 15:26:11 +0000 (17:26 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jun 2015 21:27:35 +0000 (14:27 -0700)
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>
fsck.c
diff --git a/fsck.c b/fsck.c
index 8a6ecf31a59b09dff260c7520034a106a420a289..d3d81fcc12f5852acb6e35fb355cdc0770194efd 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -537,12 +537,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 
        if (!skip_prefix(buffer, "tree ", &buffer))
                return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
-       if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
-               return report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
+       if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n') {
+               err = report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
+               if (err)
+                       return err;
+       }
        buffer += 41;
        while (skip_prefix(buffer, "parent ", &buffer)) {
-               if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
-                       return report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
+               if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
+                       err = report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
+                       if (err)
+                               return err;
+               }
                buffer += 41;
                parent_line_count++;
        }
@@ -551,11 +557,17 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
        if (graft) {
                if (graft->nr_parent == -1 && !parent_count)
                        ; /* shallow commit */
-               else if (graft->nr_parent != parent_count)
-                       return report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
+               else if (graft->nr_parent != parent_count) {
+                       err = report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
+                       if (err)
+                               return err;
+               }
        } else {
-               if (parent_count != parent_line_count)
-                       return report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
+               if (parent_count != parent_line_count) {
+                       err = report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
+                       if (err)
+                               return err;
+               }
        }
        if (!skip_prefix(buffer, "author ", &buffer))
                return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");