Skip to content

Commit a08b1d6

Browse files
committed
Merge branch 'jt/cache-tree-allow-missing-object-in-partial-clone'
In a partial clone that will lazily be hydrated from the originating repository, we generally want to avoid "does this object exist (locally)?" on objects that we deliberately omitted when we created the clone. The cache-tree codepath (which is used to write a tree object out of the index) however insisted that the object exists, even for paths that are outside of the partial checkout area. The code has been updated to avoid such a check. * jt/cache-tree-allow-missing-object-in-partial-clone: cache-tree: skip some blob checks in partial clone
2 parents 465e73f + 2f215ff commit a08b1d6

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)