Skip to content

Commit 167a575

Browse files
peffgitster
authored andcommitted
clone: use "quick" lookup while following tags
When cloning with --single-branch, we implement git-fetch's usual tag-following behavior, grabbing any tag objects that point to objects we have locally. When we're a partial clone, though, our has_object_file() check will actually lazy-fetch each tag. That not only defeats the purpose of --single-branch, but it does it incredibly slowly, potentially kicking off a new fetch for each tag. This is even worse for a shallow clone, which implies --single-branch, because even tags which are supersets of each other will be fetched individually. We can fix this by passing OBJECT_INFO_SKIP_FETCH_OBJECT to the call, which is what git-fetch does in this case. Likewise, let's include OBJECT_INFO_QUICK, as that's what git-fetch does. The rationale is discussed in 5827a03 (fetch: use "quick" has_sha1_file for tag following, 2016-10-13), but here the tradeoff would apply even more so because clone is very unlikely to be racing with another process repacking our newly-created repository. This may provide a very small speedup even in the non-partial case case, as we'd avoid calling reprepare_packed_git() for each tag (though in practice, we'd only have a single packfile, so that reprepare should be quite cheap). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e96c66 commit 167a575

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
639639
continue;
640640
if (ends_with(ref->name, "^{}"))
641641
continue;
642-
if (!has_object_file(&ref->old_oid))
642+
if (!has_object_file_with_flags(&ref->old_oid,
643+
OBJECT_INFO_QUICK |
644+
OBJECT_INFO_SKIP_FETCH_OBJECT))
643645
continue;
644646
update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
645647
UPDATE_REFS_DIE_ON_ERR);

t/t5616-partial-clone.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ test_expect_success 'verify fetch downloads only one pack when updating refs' '
405405
test_line_count = 3 pack-list
406406
'
407407

408+
test_expect_success 'single-branch tag following respects partial clone' '
409+
git clone --single-branch -b B --filter=blob:none \
410+
"file://$(pwd)/srv.bare" single &&
411+
git -C single rev-parse --verify refs/tags/B &&
412+
git -C single rev-parse --verify refs/tags/A &&
413+
test_must_fail git -C single rev-parse --verify refs/tags/C
414+
'
415+
408416
. "$TEST_DIRECTORY"/lib-httpd.sh
409417
start_httpd
410418

0 commit comments

Comments
 (0)