Skip to content

Commit aab0f89

Browse files
peffgitster
authored andcommitted
fetch: don't ask for remote HEAD if followRemoteHEAD is "never"
When we are going to consider updating the refs/remotes/*/HEAD symref, we have to ask the remote side where its HEAD points. But if we know that the feature is disabled by config, we don't need to bother! This saves a little bit of work and network communication for the server. And even a little bit of effort on the client, as our local set_head() function did a bit of work matching the remote HEAD before realizing that we're not going to do anything with it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c834d1a commit aab0f89

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

builtin/fetch.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,6 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
16431643
string_list_append(&heads, strip_refshead(ref->name));
16441644
}
16451645

1646-
if (follow_remote_head == FOLLOW_REMOTE_NEVER)
1647-
goto cleanup;
1648-
16491646
if (!heads.nr)
16501647
result = 1;
16511648
else if (heads.nr > 1)
@@ -1729,7 +1726,8 @@ static int do_fetch(struct transport *transport,
17291726
if (transport->remote->fetch.nr) {
17301727
refspec_ref_prefixes(&transport->remote->fetch,
17311728
&transport_ls_refs_options.ref_prefixes);
1732-
do_set_head = 1;
1729+
if (transport->remote->follow_remote_head != FOLLOW_REMOTE_NEVER)
1730+
do_set_head = 1;
17331731
}
17341732
if (branch_has_merge_config(branch) &&
17351733
!strcmp(branch->remote_name, transport->remote->name)) {

t/t5510-fetch.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ test_expect_success "fetch test followRemoteHEAD never" '
119119
cd two &&
120120
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
121121
git config set remote.origin.followRemoteHEAD "never" &&
122-
git fetch &&
122+
GIT_TRACE_PACKET=$PWD/trace.out git fetch &&
123+
# Confirm that we do not even ask for HEAD when we are
124+
# not going to act on it.
125+
test_grep ! "ref-prefix HEAD" trace.out &&
123126
test_must_fail git rev-parse --verify refs/remotes/origin/HEAD
124127
)
125128
'

0 commit comments

Comments
 (0)