fsck: introduce `git fsck --connectivity-only`
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 22 Jun 2015 15:27:12 +0000 (17:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jun 2015 21:27:37 +0000 (14:27 -0700)
This option avoids unpacking each and all blob objects, and just
verifies the connectivity. In particular with large repositories, this
speeds up the operation, at the expense of missing corrupt blobs,
ignoring unreachable objects and other fsck issues, if any.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-fsck.txt
builtin/fsck.c
t/t1450-fsck.sh
index 25c431d3c552d523c79473cf10867a3cab00c259..84ee92e15844588425111c1230b37ac3f0f03038 100644 (file)
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
         [--[no-]full] [--strict] [--verbose] [--lost-found]
-        [--[no-]dangling] [--[no-]progress] [<object>*]
+        [--[no-]dangling] [--[no-]progress] [--connectivity-only] [<object>*]
 
 DESCRIPTION
 -----------
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
        object pools.  This is now default; you can turn it off
        with --no-full.
 
+--connectivity-only::
+       Check only the connectivity of tags, commits and tree objects. By
+       avoiding to unpack blobs, this speeds up the operation, at the
+       expense of missing corrupt objects or other problematic issues.
+
 --strict::
        Enable more strict checking, namely to catch a file mode
        recorded with g+w bit set, which was created by older
index 6dc2f9487409397b3654adf108b18fe04c22dba1..070909ef208fe6815898b35539540c39da8448ad 100644 (file)
@@ -23,6 +23,7 @@ static int show_tags;
 static int show_unreachable;
 static int include_reflogs = 1;
 static int check_full = 1;
+static int connectivity_only;
 static int check_strict;
 static int keep_cache_objects;
 static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)
        if (!(obj->flags & HAS_OBJ)) {
                if (has_sha1_pack(obj->sha1))
                        return; /* it is in pack - forget about it */
+               if (connectivity_only && has_sha1_file(obj->sha1))
+                       return;
                printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
                errors_found |= ERROR_REACHABLE;
                return;
@@ -617,6 +620,7 @@ static struct option fsck_opts[] = {
        OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
        OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
        OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
+       OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
        OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
        OPT_BOOL(0, "lost-found", &write_lost_and_found,
                                N_("write dangling objects in .git/lost-found")),
@@ -653,7 +657,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
        git_config(fsck_config, NULL);
 
        fsck_head_link();
-       fsck_object_dir(get_object_directory());
+       if (!connectivity_only)
+               fsck_object_dir(get_object_directory());
 
        prepare_alt_odb();
        for (alt = alt_odb_list; alt; alt = alt->next) {
index 17271295f37f964a981a86eb7451ca59538f2454..956673b8a14d39ef6bece7629b2407b0c10a071a 100755 (executable)
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
        test_must_fail git -C missing fsck
 '
 
+test_expect_success 'fsck --connectivity-only' '
+       rm -rf connectivity-only &&
+       git init connectivity-only &&
+       (
+               cd connectivity-only &&
+               touch empty &&
+               git add empty &&
+               test_commit empty &&
+               empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+               rm -f $empty &&
+               echo invalid >$empty &&
+               test_must_fail git fsck --strict &&
+               git fsck --strict --connectivity-only &&
+               tree=$(git rev-parse HEAD:) &&
+               suffix=${tree#??} &&
+               tree=.git/objects/${tree%$suffix}/$suffix &&
+               rm -f $tree &&
+               echo invalid >$tree &&
+               test_must_fail git fsck --strict --connectivity-only
+       )
+'
+
 test_done