fetch: generate ref-prefixes when using a configured refspec

Teach fetch to generate ref-prefixes, to be used for server-side filtering of the ref-advertisement, based on the configured fetch refspec ('remote.<name>.fetch') when no user provided refspec exists. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 16, 2018 at 16:48 UTC dcc73cf7ffd17e68bda05fff4c139465580aff28
2 files changed +23 -1
builtin/fetch.c
+9 -1
@@ -351,7 +351,15 @@ static struct ref *get_ref_map(struct transport *transport,
351
352 const struct ref *remote_refs;
353
354 - refspec_ref_prefixes(rs, &ref_prefixes);
354 + if (rs->nr)
355 + refspec_ref_prefixes(rs, &ref_prefixes);
356 + else if (transport->remote && transport->remote->fetch.nr)
357 + refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
358 +
359 + if (ref_prefixes.argc &&
360 + (tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) {
361 + argv_array_push(&ref_prefixes, "refs/tags/");
362 + }
363
364 remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
365
t/t5702-protocol-v2.sh
+14
@@ -201,6 +201,20 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
201 ! grep "refs/tags/three" log
202 '
203
204 +test_expect_success 'default refspec is used to filter ref when fetchcing' '
205 + test_when_finished "rm -f log" &&
206 +
207 + GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
208 + fetch origin &&
209 +
210 + git -C file_child log -1 --format=%s three >actual &&
211 + git -C file_parent log -1 --format=%s three >expect &&
212 + test_cmp expect actual &&
213 +
214 + grep "ref-prefix refs/heads/" log &&
215 + grep "ref-prefix refs/tags/" log
216 +'
217 +
218 # Test protocol v2 with 'http://' transport
219 #
220 . "$TEST_DIRECTORY"/lib-httpd.sh