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>

Brandon Williams committed Mar 15, 2018 at 10:31 UTC 1af8ae1cfa44a3f3c3f1efb7f9ebe68bc0ce7578
6 files changed +21 -8
builtin/clone.c
+1 -1
@@ -1104,7 +1104,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1104 if (transport->smart_options && !deepen)
1105 transport->smart_options->check_self_contained_and_connected = 1;
1106
1107 - refs = transport_get_remote_refs(transport);
1107 + refs = transport_get_remote_refs(transport, NULL);
1108
1109 if (refs) {
1110 mapped_refs = wanted_peer_refs(refs, refspec);
builtin/fetch.c
+2 -2
@@ -250,7 +250,7 @@ static void find_non_local_tags(struct transport *transport,
250 struct string_list_item *item = NULL;
251
252 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) {
254 if (!starts_with(ref->name, "refs/tags/"))
255 continue;
256
@@ -336,7 +336,7 @@ static struct ref *get_ref_map(struct transport *transport,
336 /* opportunistically-updated references: */
337 struct ref *orefs = NULL, **oref_tail = &orefs;
338
339 - const struct ref *remote_refs = transport_get_remote_refs(transport);
339 + const struct ref *remote_refs = transport_get_remote_refs(transport, NULL);
340
341 if (refspec_count) {
342 struct refspec *fetch_refspec;
builtin/ls-remote.c
+1 -1
@@ -96,7 +96,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
96 if (uploadpack != NULL)
97 transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
98
99 - ref = transport_get_remote_refs(transport);
99 + ref = transport_get_remote_refs(transport, NULL);
100 if (transport_disconnect(transport))
101 return 1;
102
builtin/remote.c
+1 -1
@@ -862,7 +862,7 @@ static int get_remote_ref_states(const char *name,
862 if (query) {
863 transport = transport_get(states->remote, states->remote->url_nr > 0 ?
864 states->remote->url[0] : NULL);
865 - remote_refs = transport_get_remote_refs(transport);
865 + remote_refs = transport_get_remote_refs(transport, NULL);
866 transport_disconnect(transport);
867
868 states->queried = 1;
transport.c
+5 -2
@@ -1138,10 +1138,13 @@ int transport_push(struct transport *transport,
1138 return 1;
1139 }
1140
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)
1143 {
1144 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);
1148 transport->got_remote_refs = 1;
1149 }
1150
transport.h
+11 -1
@@ -178,7 +178,17 @@ int transport_push(struct transport *connection,
178 int refspec_nr, const char **refspec, int flags,
179 unsigned int * reject_reasons);
180
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);
192
193 int transport_fetch_refs(struct transport *transport, struct ref *refs);
194 void transport_unlock_pack(struct transport *transport);