From ffb2c0fe5c2dbfe2be0a4743ffed622295e1124c Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 14 Mar 2018 11:42:40 -0700 Subject: [PATCH 1/2] index-pack: support checking objects but not links The index-pack command currently supports the --check-self-contained-and-connected argument, for internal use only, that instructs it to only check for broken links and not broken objects. For partial clones, we need the inverse, so add a --fsck-objects argument that checks for broken objects and not broken links, also for internal use only. This will be used by fetch-pack in a subsequent patch. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- Documentation/git-index-pack.txt | 3 +++ builtin/index-pack.c | 6 ++++-- t/t5302-pack-index.sh | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/git-index-pack.txt b/Documentation/git-index-pack.txt index 1b4b65d6657..138edb47b6a 100644 --- a/Documentation/git-index-pack.txt +++ b/Documentation/git-index-pack.txt @@ -77,6 +77,9 @@ OPTIONS --check-self-contained-and-connected:: Die if the pack contains broken links. For internal use only. +--fsck-objects:: + Die if the pack contains broken objects. For internal use only. + --threads=:: Specifies the number of threads to spawn when resolving deltas. This requires that index-pack be compiled with diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9791d428892..bda84a92eff 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -828,7 +828,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, free(has_data); } - if (strict) { + if (strict || do_fsck_object) { read_lock(); if (type == OBJ_BLOB) { struct blob *blob = lookup_blob(oid); @@ -854,7 +854,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, if (do_fsck_object && fsck_object(obj, buf, size, &fsck_options)) die(_("Error in object")); - if (fsck_walk(obj, NULL, &fsck_options)) + if (strict && fsck_walk(obj, NULL, &fsck_options)) die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid)); if (obj->type == OBJ_TREE) { @@ -1689,6 +1689,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) } else if (!strcmp(arg, "--check-self-contained-and-connected")) { strict = 1; check_self_contained_and_connected = 1; + } else if (!strcmp(arg, "--fsck-objects")) { + do_fsck_object = 1; } else if (!strcmp(arg, "--verify")) { verify = 1; } else if (!strcmp(arg, "--verify-stat")) { diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index c2fc584dac3..d695a6082ed 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -262,4 +262,9 @@ EOF grep "^warning:.* expected .tagger. line" err ' +test_expect_success 'index-pack --fsck-objects also warns upon missing tagger in tag' ' + git index-pack --fsck-objects tag-test-${pack1}.pack 2>err && + grep "^warning:.* expected .tagger. line" err +' + test_done From 98a2ea46c2dedf45b5a94335462547a5d78a68e2 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 14 Mar 2018 11:42:41 -0700 Subject: [PATCH 2/2] fetch-pack: do not check links for partial fetch When doing a partial clone or fetch with transfer.fsckobjects=1, use the --fsck-objects instead of the --strict flag when invoking index-pack so that links are not checked, only objects. This is because incomplete links are expected when doing a partial clone or fetch. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- fetch-pack.c | 13 +++++++++++-- t/t5616-partial-clone.sh | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index d97461296d5..1d6117565c2 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -886,8 +886,17 @@ static int get_pack(struct fetch_pack_args *args, ? fetch_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects - : 0) - argv_array_push(&cmd.args, "--strict"); + : 0) { + if (args->from_promisor) + /* + * We cannot use --strict in index-pack because it + * checks both broken objects and links, but we only + * want to check for broken objects. + */ + argv_array_push(&cmd.args, "--fsck-objects"); + else + argv_array_push(&cmd.args, "--strict"); + } cmd.in = demux.out; cmd.git_cmd = 1; diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 29d86311843..cee55653675 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -143,4 +143,15 @@ test_expect_success 'manual prefetch of missing objects' ' test_line_count = 0 observed.oids ' +test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' ' + git init src && + test_commit -C src x && + test_config -C src uploadpack.allowfilter 1 && + test_config -C src uploadpack.allowanysha1inwant 1 && + + GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \ + clone --filter="blob:none" "file://$(pwd)/src" dst && + grep "git index-pack.*--fsck-objects" trace +' + test_done