transport: convert transport_get_remote_refs to take a list of ref prefixes
authorBrandon Williams <bmwill@google.com>
Thu, 15 Mar 2018 17:31:23 +0000 (10:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Mar 2018 19:01:08 +0000 (12:01 -0700)
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>
builtin/clone.c
builtin/fetch.c
builtin/ls-remote.c
builtin/remote.c
transport.c
transport.h
index 2da71db10752bf95647052dcd5b7c4b28e7a50ac..4db3079acc03a2da3bf528ed545bbf465abad767 100644 (file)
@@ -1104,7 +1104,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (transport->smart_options && !deepen)
                transport->smart_options->check_self_contained_and_connected = 1;
 
-       refs = transport_get_remote_refs(transport);
+       refs = transport_get_remote_refs(transport, NULL);
 
        if (refs) {
                mapped_refs = wanted_peer_refs(refs, refspec);
index 7bbcd26faf1fe650ccc7dbbd526db5114aac0c8f..850382f5596cf78bfa2cf8ccd66fcf8ec7f72e0d 100644 (file)
@@ -250,7 +250,7 @@ static void find_non_local_tags(struct transport *transport,
        struct string_list_item *item = NULL;
 
        for_each_ref(add_existing, &existing_refs);
-       for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
+       for (ref = transport_get_remote_refs(transport, NULL); ref; ref = ref->next) {
                if (!starts_with(ref->name, "refs/tags/"))
                        continue;
 
@@ -336,7 +336,7 @@ static struct ref *get_ref_map(struct transport *transport,
        /* opportunistically-updated references: */
        struct ref *orefs = NULL, **oref_tail = &orefs;
 
-       const struct ref *remote_refs = transport_get_remote_refs(transport);
+       const struct ref *remote_refs = transport_get_remote_refs(transport, NULL);
 
        if (refspec_count) {
                struct refspec *fetch_refspec;
index c4be98ab9e84fdcde2842b88d4bb60600f7bf627..c6e9847c5c8d10662c30d4925f2cf62a7eba1083 100644 (file)
@@ -96,7 +96,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        if (uploadpack != NULL)
                transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
-       ref = transport_get_remote_refs(transport);
+       ref = transport_get_remote_refs(transport, NULL);
        if (transport_disconnect(transport))
                return 1;
 
index d95bf904c3b3fb40438335198a2729e45a9897cb..d0b6ff6e29a5f907dd9ca012e7f5f66ae97729a8 100644 (file)
@@ -862,7 +862,7 @@ static int get_remote_ref_states(const char *name,
        if (query) {
                transport = transport_get(states->remote, states->remote->url_nr > 0 ?
                        states->remote->url[0] : NULL);
-               remote_refs = transport_get_remote_refs(transport);
+               remote_refs = transport_get_remote_refs(transport, NULL);
                transport_disconnect(transport);
 
                states->queried = 1;
index 2e68010dd05d729415a9cb9da3a532755335d565..3f130518d2ba79a1f7ba9d96c0db04f6b97e50c8 100644 (file)
@@ -1138,10 +1138,13 @@ int transport_push(struct transport *transport,
        return 1;
 }
 
-const struct ref *transport_get_remote_refs(struct transport *transport)
+const struct ref *transport_get_remote_refs(struct transport *transport,
+                                           const struct argv_array *ref_prefixes)
 {
        if (!transport->got_remote_refs) {
-               transport->remote_refs = transport->vtable->get_refs_list(transport, 0, NULL);
+               transport->remote_refs =
+                       transport->vtable->get_refs_list(transport, 0,
+                                                        ref_prefixes);
                transport->got_remote_refs = 1;
        }
 
index 731c78b6795740f8e9bfb80741b0170671b37dd3..83992a4257e26b70039a3cedf9b6dde822558914 100644 (file)
@@ -178,7 +178,17 @@ int transport_push(struct transport *connection,
                   int refspec_nr, const char **refspec, int flags,
                   unsigned int * reject_reasons);
 
-const struct ref *transport_get_remote_refs(struct transport *transport);
+/*
+ * Retrieve refs from a remote.
+ *
+ * Optionally a list of ref prefixes can be provided which can be sent to the
+ * server (when communicating using protocol v2) to enable it to limit the ref
+ * advertisement.  Since ref filtering is done on the server's end (and only
+ * when using protocol v2), this can return refs which don't match the provided
+ * ref_prefixes.
+ */
+const struct ref *transport_get_remote_refs(struct transport *transport,
+                                           const struct argv_array *ref_prefixes);
 
 int transport_fetch_refs(struct transport *transport, struct ref *refs);
 void transport_unlock_pack(struct transport *transport);