fsck: support demoting errors to warnings

We already have support in `git receive-pack` to deal with some legacy repositories which have non-fatal issues. Let's make `git fsck` itself useful with such repositories, too, by allowing users to ignore known issues, or at least demote those issues to mere warnings. Example: `git -c fsck.missingEmail=ignore fsck` would hide problems with missing emails in author, committer and tagger lines. In the same spirit that `git receive-pack`'s usage of the fsck machinery differs from `git fsck`'s – some of the non-fatal warnings in `git fsck` are fatal with `git receive-pack` when receive.fsckObjects = true, for example – we strictly separate the fsck.<msg-id> from the receive.fsck.<msg-id> settings. 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:27 UTC 2becf00ff70b324999d0e3046d828a80884ab561
3 files changed +34
Documentation/config.txt
+11
@@ -1242,6 +1242,17 @@ filter.<driver>.smudge::
1242 object to a worktree file upon checkout. See
1243 linkgit:gitattributes[5] for details.
1244
1245 +fsck.<msg-id>::
1246 + Allows overriding the message type (error, warn or ignore) of a
1247 + specific message ID such as `missingEmail`.
1248 ++
1249 +For convenience, fsck prefixes the error/warning with the message ID,
1250 +e.g. "missingEmail: invalid author/committer line - missing email" means
1251 +that setting `fsck.missingEmail = ignore` will hide that issue.
1252 ++
1253 +This feature is intended to support working with legacy repositories
1254 +which cannot be repaired without disruptive changes.
1255 +
1256 gc.aggressiveDepth::
1257 The depth parameter used in the delta compression
1258 algorithm used by 'git gc --aggressive'. This defaults
builtin/fsck.c
+12
@@ -46,6 +46,16 @@ static int show_dangling = 1;
46 #define DIRENT_SORT_HINT(de) ((de)->d_ino)
47 #endif
48
49 +static int fsck_config(const char *var, const char *value, void *cb)
50 +{
51 + if (skip_prefix(var, "fsck.", &var)) {
52 + fsck_set_msg_type(&fsck_obj_options, var, value);
53 + return 0;
54 + }
55 +
56 + return git_default_config(var, value, cb);
57 +}
58 +
59 static void objreport(struct object *obj, const char *msg_type,
60 const char *err)
61 {
@@ -640,6 +650,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
650 include_reflogs = 0;
651 }
652
653 + git_config(fsck_config, NULL);
654 +
655 fsck_head_link();
656 fsck_object_dir(get_object_directory());
657
t/t1450-fsck.sh
+11
@@ -287,6 +287,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
287 grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
288 '
289
290 +test_expect_success 'force fsck to ignore double author' '
291 + git cat-file commit HEAD >basis &&
292 + sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
293 + new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
294 + test_when_finished "remove_object $new" &&
295 + git update-ref refs/heads/bogus "$new" &&
296 + test_when_finished "git update-ref -d refs/heads/bogus" &&
297 + test_must_fail git fsck &&
298 + git -c fsck.multipleAuthors=ignore fsck
299 +'
300 +
301 _bz='\0'
302 _bz5="$_bz$_bz$_bz$_bz$_bz"
303 _bz20="$_bz5$_bz5$_bz5$_bz5"