cache-tree: skip some blob checks in partial clone

In a partial clone, whenever a sparse checkout occurs, the existence of all blobs in the index is verified, whether they are included or excluded by the .git/info/sparse-checkout specification. This significantly degrades performance because a lazy fetch occurs whenever the existence of a missing blob is checked. This is because cache_tree_update() checks the existence of all objects in the index, whether or not CE_SKIP_WORKTREE is set on them. Teach cache_tree_update() to skip checking CE_SKIP_WORKTREE objects when the repository is a partial clone. This improves performance for sparse checkout and also other operations that use cache_tree_update(). Instead of completely removing the check, an argument could be made that the check should instead be replaced by a check that the blob is promised, but for performance reasons, I decided not to do this. If the user needs to verify the repository, it can be done using fsck (which will notify if a tree points to a missing and non-promised blob, whether the blob is included or excluded by the sparse-checkout specification). Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Oct 9, 2018 at 11:40 UTC 2f215ff10bdf02f6c760ea34968fc39ae75ae449
2 files changed +38 -1
cache-tree.c
+5 -1
@@ -326,6 +326,7 @@ static int update_one(struct cache_tree *it,
326 unsigned mode;
327 int expected_missing = 0;
328 int contains_ita = 0;
329 + int ce_missing_ok;
330
331 path = ce->name;
332 pathlen = ce_namelen(ce);
@@ -355,8 +356,11 @@ static int update_one(struct cache_tree *it,
356 i++;
357 }
358
359 + ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
360 + (repository_format_partial_clone &&
361 + ce_skip_worktree(ce));
362 if (is_null_oid(oid) ||
359 - (mode != S_IFGITLINK && !missing_ok && !has_object_file(oid))) {
363 + (!ce_missing_ok && !has_object_file(oid))) {
364 strbuf_release(&buffer);
365 if (expected_missing)
366 return -1;
t/t1090-sparse-checkout-scope.sh
+33
@@ -63,4 +63,37 @@ test_expect_success 'return to full checkout of master' '
63 test "$(cat b)" = "modified"
64 '
65
66 +test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' '
67 + test_create_repo server &&
68 + git clone "file://$(pwd)/server" client &&
69 +
70 + test_config -C server uploadpack.allowfilter 1 &&
71 + test_config -C server uploadpack.allowanysha1inwant 1 &&
72 + echo a >server/a &&
73 + echo bb >server/b &&
74 + mkdir server/c &&
75 + echo ccc >server/c/c &&
76 + git -C server add a b c/c &&
77 + git -C server commit -m message &&
78 +
79 + test_config -C client core.sparsecheckout 1 &&
80 + test_config -C client extensions.partialclone origin &&
81 + echo "!/*" >client/.git/info/sparse-checkout &&
82 + echo "/a" >>client/.git/info/sparse-checkout &&
83 + git -C client fetch --filter=blob:none origin &&
84 + git -C client checkout FETCH_HEAD &&
85 +
86 + git -C client rev-list HEAD \
87 + --quiet --objects --missing=print >unsorted_actual &&
88 + (
89 + printf "?" &&
90 + git hash-object server/b &&
91 + printf "?" &&
92 + git hash-object server/c/c
93 + ) >unsorted_expect &&
94 + sort unsorted_actual >actual &&
95 + sort unsorted_expect >expect &&
96 + test_cmp expect actual
97 +'
98 +
99 test_done