fsck: introduce `git fsck --connectivity-only`
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>
Johannes Schindelin committed
Jun 22, 2015 at 17:27 UTC
02976bf856bc47ea2bcb9423cd13b6f69ce58929
3 files changed
+34
-2
Documentation/git-fsck.txt
+6
-1
@@ -11,7 +11,7 @@ SYNOPSIS
11
[verse]
12
'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
13
[--[no-]full] [--strict] [--verbose] [--lost-found]
14
- [--[no-]dangling] [--[no-]progress] [<object>*]
14
+ [--[no-]dangling] [--[no-]progress] [--connectivity-only] [<object>*]
15
16
DESCRIPTION
17
-----------
@@ -60,6 +60,11 @@ index file, all SHA-1 references in `refs` namespace, and all reflogs
60
object pools. This is now default; you can turn it off
61
with --no-full.
62
63
+--connectivity-only::
64
+ Check only the connectivity of tags, commits and tree objects. By
65
+ avoiding to unpack blobs, this speeds up the operation, at the
66
+ expense of missing corrupt objects or other problematic issues.
67
+
68
--strict::
69
Enable more strict checking, namely to catch a file mode
70
recorded with g+w bit set, which was created by older
builtin/fsck.c
+6
-1
@@ -23,6 +23,7 @@ static int show_tags;
23
static int show_unreachable;
24
static int include_reflogs = 1;
25
static int check_full = 1;
26
+static int connectivity_only;
27
static int check_strict;
28
static int keep_cache_objects;
29
static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
@@ -181,6 +182,8 @@ static void check_reachable_object(struct object *obj)
182
if (!(obj->flags & HAS_OBJ)) {
183
if (has_sha1_pack(obj->sha1))
184
return; /* it is in pack - forget about it */
185
+ if (connectivity_only && has_sha1_file(obj->sha1))
186
+ return;
187
printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
188
errors_found |= ERROR_REACHABLE;
189
return;
@@ -617,6 +620,7 @@ static struct option fsck_opts[] = {
620
OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
621
OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
622
OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
623
+ OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
624
OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
625
OPT_BOOL(0, "lost-found", &write_lost_and_found,
626
N_("write dangling objects in .git/lost-found")),
@@ -653,7 +657,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
657
git_config(fsck_config, NULL);
658
659
fsck_head_link();
656
- fsck_object_dir(get_object_directory());
660
+ if (!connectivity_only)
661
+ fsck_object_dir(get_object_directory());
662
663
prepare_alt_odb();
664
for (alt = alt_odb_list; alt; alt = alt->next) {
t/t1450-fsck.sh
+22
@@ -431,4 +431,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
431
test_must_fail git -C missing fsck
432
'
433
434
+test_expect_success 'fsck --connectivity-only' '
435
+ rm -rf connectivity-only &&
436
+ git init connectivity-only &&
437
+ (
438
+ cd connectivity-only &&
439
+ touch empty &&
440
+ git add empty &&
441
+ test_commit empty &&
442
+ empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
443
+ rm -f $empty &&
444
+ echo invalid >$empty &&
445
+ test_must_fail git fsck --strict &&
446
+ git fsck --strict --connectivity-only &&
447
+ tree=$(git rev-parse HEAD:) &&
448
+ suffix=${tree#??} &&
449
+ tree=.git/objects/${tree%$suffix}/$suffix &&
450
+ rm -f $tree &&
451
+ echo invalid >$tree &&
452
+ test_must_fail git fsck --strict --connectivity-only
453
+ )
454
+'
455
+
456
test_done