Skip to content

Commit f981ec1

Browse files
jonathantanmygitster
authored andcommitted
cache-tree: do not lazy-fetch tentative tree
The cache-tree datastructure is used to speed up the comparison between the HEAD and the index, and when the index is updated by a cherry-pick (for example), a tree object that would represent the paths in the index in a directory is constructed in-core, to see if such a tree object exists already in the object store. When the lazy-fetch mechanism was introduced, we converted this "does the tree exist?" check into an "if it does not, and if we lazily cloned, see if the remote has it" call by mistake. Since the whole point of this check is to repair the cache-tree by recording an already existing tree object opportunistically, we shouldn't even try to fetch one from the remote. Pass the OBJECT_INFO_SKIP_FETCH_OBJECT flag to make sure we only check for existence in the local object store without triggering the lazy fetch mechanism. Signed-off-by: Jonathan Tan <[email protected]> [jc: rewritten the proposed log message] Signed-off-by: Junio C Hamano <[email protected]>
1 parent 745f681 commit f981ec1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static int update_one(struct cache_tree *it,
407407
if (repair) {
408408
struct object_id oid;
409409
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
410-
if (has_object_file(&oid))
410+
if (has_object_file_with_flags(&oid, OBJECT_INFO_SKIP_FETCH_OBJECT))
411411
oidcpy(&it->oid, &oid);
412412
else
413413
to_invalidate = 1;

t/t0410-partial-clone.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,20 @@ test_expect_success 'gc stops traversal when a missing but promised object is re
492492
! grep "$TREE_HASH" out
493493
'
494494

495+
test_expect_success 'do not fetch when checking existence of tree we construct ourselves' '
496+
rm -rf repo &&
497+
test_create_repo repo &&
498+
test_commit -C repo base &&
499+
test_commit -C repo side1 &&
500+
git -C repo checkout base &&
501+
test_commit -C repo side2 &&
502+
503+
git -C repo config core.repositoryformatversion 1 &&
504+
git -C repo config extensions.partialclone "arbitrary string" &&
505+
506+
git -C repo cherry-pick side1
507+
'
508+
495509
. "$TEST_DIRECTORY"/lib-httpd.sh
496510
start_httpd
497511

0 commit comments

Comments
 (0)