]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport: teach all vtables to allow fetch first
authorJonathan Tan <jonathantanmy@google.com>
Wed, 21 Aug 2019 22:20:10 +0000 (15:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2019 21:20:39 +0000 (14:20 -0700)
The only transport that does not allow fetch() to be called before
get_refs_list() is the bundle transport. Clean up the code by teaching
the bundle transport the ability to do this, and removing support for
transports that don't support this order of invocation.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5607-clone-bundle.sh
transport-helper.c
transport-internal.h
transport.c

index 2a0fb15cf175251df0a140aa4f5c56fd7885292d..b7a3fdf02dfb4096133d1aca8de412d907ea921b 100755 (executable)
@@ -83,4 +83,15 @@ test_expect_success 'failed bundle creation does not leave cruft' '
        test_path_is_missing fail.bundle.lock
 '
 
+test_expect_success 'fetch SHA-1 from bundle' '
+       test_create_repo foo &&
+       test_commit -C foo x &&
+       git -C foo bundle create tip.bundle -1 master &&
+       git -C foo rev-parse HEAD >hash &&
+
+       # Exercise to ensure that fetching a SHA-1 from a bundle works with no
+       # errors
+       git fetch --no-tags foo/tip.bundle "$(cat hash)"
+'
+
 test_done
index 1fb31e1a6e31d8f5c383116a8abb0c43c87c528b..96955d4004a8f5feaac1a5cc9baa189c67597f16 100644 (file)
@@ -1146,7 +1146,6 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
 }
 
 static struct transport_vtable vtable = {
-       1,
        set_helper_option,
        get_refs_list,
        fetch,
index 004bee5e368f24963d925af997aec051189e1acf..1cde6258a73bcf8582b0746d1c44a23b30115dc9 100644 (file)
@@ -6,12 +6,6 @@ struct transport;
 struct argv_array;
 
 struct transport_vtable {
-       /**
-        * This transport supports the fetch() function being called
-        * without get_refs_list() first being called.
-        */
-       unsigned fetch_without_list : 1;
-
        /**
         * Returns 0 if successful, positive if the option is not
         * recognized or is inapplicable, and negative if the option
index 778c60bf573a714134435e438da5d390fa490484..662a2d9ae0bfb0a82596bc693d30e7f49595b934 100644 (file)
@@ -122,6 +122,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 struct bundle_transport_data {
        int fd;
        struct bundle_header header;
+       unsigned get_refs_from_bundle_called : 1;
 };
 
 static struct ref *get_refs_from_bundle(struct transport *transport,
@@ -135,6 +136,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
        if (for_push)
                return NULL;
 
+       data->get_refs_from_bundle_called = 1;
+
        if (data->fd > 0)
                close(data->fd);
        data->fd = read_bundle_header(transport->url, &data->header);
@@ -154,6 +157,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct bundle_transport_data *data = transport->data;
+
+       if (!data->get_refs_from_bundle_called)
+               get_refs_from_bundle(transport, 0, NULL);
        return unbundle(the_repository, &data->header, data->fd,
                        transport->progress ? BUNDLE_VERBOSE : 0);
 }
@@ -742,7 +748,6 @@ static int disconnect_git(struct transport *transport)
 }
 
 static struct transport_vtable taken_over_vtable = {
-       1,
        NULL,
        get_refs_via_connect,
        fetch_refs_via_pack,
@@ -892,7 +897,6 @@ void transport_check_allowed(const char *type)
 }
 
 static struct transport_vtable bundle_vtable = {
-       0,
        NULL,
        get_refs_from_bundle,
        fetch_refs_from_bundle,
@@ -902,7 +906,6 @@ static struct transport_vtable bundle_vtable = {
 };
 
 static struct transport_vtable builtin_smart_vtable = {
-       1,
        NULL,
        get_refs_via_connect,
        fetch_refs_via_pack,
@@ -1285,15 +1288,6 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
        struct ref **heads = NULL;
        struct ref *rm;
 
-       if (!transport->vtable->fetch_without_list)
-               /*
-                * Some transports (e.g. the built-in bundle transport and the
-                * transport helper interface) do not work when fetching is
-                * done immediately after transport creation. List the remote
-                * refs anyway (if not already listed) as a workaround.
-                */
-               transport_get_remote_refs(transport, NULL);
-
        for (rm = refs; rm; rm = rm->next) {
                nr_refs++;
                if (rm->peer_ref &&