Skip to content

Commit 2f215ff

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2efbb7f commit 2f215ff

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

cache-tree.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static int update_one(struct cache_tree *it,
326326
unsigned mode;
327327
int expected_missing = 0;
328328
int contains_ita = 0;
329+
int ce_missing_ok;
329330

330331
path = ce->name;
331332
pathlen = ce_namelen(ce);
@@ -355,8 +356,11 @@ static int update_one(struct cache_tree *it,
355356
i++;
356357
}
357358

359+
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
360+
(repository_format_partial_clone &&
361+
ce_skip_worktree(ce));
358362
if (is_null_oid(oid) ||
359-
(mode != S_IFGITLINK && !missing_ok && !has_object_file(oid))) {
363+
(!ce_missing_ok && !has_object_file(oid))) {
360364
strbuf_release(&buffer);
361365
if (expected_missing)
362366
return -1;

t/t1090-sparse-checkout-scope.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,37 @@ test_expect_success 'return to full checkout of master' '
6363
test "$(cat b)" = "modified"
6464
'
6565

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+
6699
test_done

0 commit comments

Comments
 (0)