fetch: do not list refs if fetching only hashes

If only hash literals are given on a "git fetch" command-line, tag
following is not requested, and the fetch is done using protocol v2, a
list of refs is not required from the remote. Therefore, optimize by
invoking transport_get_remote_refs() only if we need the refs.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan
2018-09-27 12:24:07 -07:00
committed by Junio C Hamano
parent 6ab4055775
commit e70a3030e7
3 changed files with 54 additions and 6 deletions

View File

@ -79,6 +79,19 @@ test_expect_success 'fetch with git:// using protocol v2' '
grep "fetch< version 2" log
'
test_expect_success 'fetch by hash without tag following with protocol v2 does not list refs' '
test_when_finished "rm -f log" &&
test_commit -C "$daemon_parent" two_a &&
git -C "$daemon_parent" rev-parse two_a >two_a_hash &&
GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
fetch --no-tags origin $(cat two_a_hash) &&
grep "fetch< version 2" log &&
! grep "fetch> command=ls-refs" log
'
test_expect_success 'pull with git:// using protocol v2' '
test_when_finished "rm -f log" &&