Skip to content

Commit 1af8ae1

Browse files
bmwillgitster
authored andcommitted
transport: convert transport_get_remote_refs to take a list of ref prefixes
Teach transport_get_remote_refs() to accept a list of ref prefixes, which will be sent to the server for use in filtering when using protocol v2. (This list will be ignored when not using protocol v2.) Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 834cf34 commit 1af8ae1

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11041104
if (transport->smart_options && !deepen)
11051105
transport->smart_options->check_self_contained_and_connected = 1;
11061106

1107-
refs = transport_get_remote_refs(transport);
1107+
refs = transport_get_remote_refs(transport, NULL);
11081108

11091109
if (refs) {
11101110
mapped_refs = wanted_peer_refs(refs, refspec);

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static void find_non_local_tags(struct transport *transport,
250250
struct string_list_item *item = NULL;
251251

252252
for_each_ref(add_existing, &existing_refs);
253-
for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
253+
for (ref = transport_get_remote_refs(transport, NULL); ref; ref = ref->next) {
254254
if (!starts_with(ref->name, "refs/tags/"))
255255
continue;
256256

@@ -336,7 +336,7 @@ static struct ref *get_ref_map(struct transport *transport,
336336
/* opportunistically-updated references: */
337337
struct ref *orefs = NULL, **oref_tail = &orefs;
338338

339-
const struct ref *remote_refs = transport_get_remote_refs(transport);
339+
const struct ref *remote_refs = transport_get_remote_refs(transport, NULL);
340340

341341
if (refspec_count) {
342342
struct refspec *fetch_refspec;

builtin/ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9696
if (uploadpack != NULL)
9797
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
9898

99-
ref = transport_get_remote_refs(transport);
99+
ref = transport_get_remote_refs(transport, NULL);
100100
if (transport_disconnect(transport))
101101
return 1;
102102

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static int get_remote_ref_states(const char *name,
862862
if (query) {
863863
transport = transport_get(states->remote, states->remote->url_nr > 0 ?
864864
states->remote->url[0] : NULL);
865-
remote_refs = transport_get_remote_refs(transport);
865+
remote_refs = transport_get_remote_refs(transport, NULL);
866866
transport_disconnect(transport);
867867

868868
states->queried = 1;

transport.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,13 @@ int transport_push(struct transport *transport,
11381138
return 1;
11391139
}
11401140

1141-
const struct ref *transport_get_remote_refs(struct transport *transport)
1141+
const struct ref *transport_get_remote_refs(struct transport *transport,
1142+
const struct argv_array *ref_prefixes)
11421143
{
11431144
if (!transport->got_remote_refs) {
1144-
transport->remote_refs = transport->vtable->get_refs_list(transport, 0, NULL);
1145+
transport->remote_refs =
1146+
transport->vtable->get_refs_list(transport, 0,
1147+
ref_prefixes);
11451148
transport->got_remote_refs = 1;
11461149
}
11471150

transport.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,17 @@ int transport_push(struct transport *connection,
178178
int refspec_nr, const char **refspec, int flags,
179179
unsigned int * reject_reasons);
180180

181-
const struct ref *transport_get_remote_refs(struct transport *transport);
181+
/*
182+
* Retrieve refs from a remote.
183+
*
184+
* Optionally a list of ref prefixes can be provided which can be sent to the
185+
* server (when communicating using protocol v2) to enable it to limit the ref
186+
* advertisement. Since ref filtering is done on the server's end (and only
187+
* when using protocol v2), this can return refs which don't match the provided
188+
* ref_prefixes.
189+
*/
190+
const struct ref *transport_get_remote_refs(struct transport *transport,
191+
const struct argv_array *ref_prefixes);
182192

183193
int transport_fetch_refs(struct transport *transport, struct ref *refs);
184194
void transport_unlock_pack(struct transport *transport);

0 commit comments

Comments
 (0)