Skip to content

Commit 6ab4055

Browse files
jonathantanmygitster
authored andcommitted
transport: list refs before fetch if necessary
The built-in bundle transport and the transport helper interface do not work when transport_fetch_refs() is called immediately after transport creation. This will be needed in a subsequent patch, so fix this. Evidence: fetch_refs_from_bundle() relies on data->header being initialized in get_refs_from_bundle(), and fetch() in transport-helper.c relies on either data->fetch or data->import being set by get_helper(), but neither transport_helper_init() nor fetch() calls get_helper(). Up until the introduction of the partial clone feature, this has not been a problem, because transport_fetch_refs() is always called after transport_get_remote_refs(). With the introduction of the partial clone feature, which involves calling transport_fetch_refs() (to fetch objects by their OIDs) without transport_get_remote_refs(), this is still not a problem, but only coincidentally - we do not support partially cloning a bundle, and as for cloning using a transport-helper-using protocol, it so happens that before transport_fetch_refs() is called, fetch_refs() in fetch-object.c calls transport_set_option(), which means that the aforementioned get_helper() is invoked through set_helper_option() in transport-helper.c. This could be fixed by fixing the transports themselves, but it doesn't seem like a good idea to me to open up previously untested code paths; also, there may be transport helpers in the wild that assume that "list" is always called before "fetch". Instead, fix this by having transport_fetch_refs() call transport_get_remote_refs() to ensure that the latter is always called at least once, unless the transport explicitly states that it supports fetching without listing refs. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0177565 commit 6ab4055

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

transport-helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
11051105
}
11061106

11071107
static struct transport_vtable vtable = {
1108+
0,
11081109
set_helper_option,
11091110
get_refs_list,
11101111
fetch,

transport-internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ struct transport;
66
struct argv_array;
77

88
struct transport_vtable {
9+
/**
10+
* This transport supports the fetch() function being called
11+
* without get_refs_list() first being called.
12+
*/
13+
unsigned fetch_without_list : 1;
14+
915
/**
1016
* Returns 0 if successful, positive if the option is not
1117
* recognized or is inapplicable, and negative if the option

transport.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ static int disconnect_git(struct transport *transport)
733733
}
734734

735735
static struct transport_vtable taken_over_vtable = {
736+
1,
736737
NULL,
737738
get_refs_via_connect,
738739
fetch_refs_via_pack,
@@ -882,6 +883,7 @@ void transport_check_allowed(const char *type)
882883
}
883884

884885
static struct transport_vtable bundle_vtable = {
886+
0,
885887
NULL,
886888
get_refs_from_bundle,
887889
fetch_refs_from_bundle,
@@ -891,6 +893,7 @@ static struct transport_vtable bundle_vtable = {
891893
};
892894

893895
static struct transport_vtable builtin_smart_vtable = {
896+
1,
894897
NULL,
895898
get_refs_via_connect,
896899
fetch_refs_via_pack,
@@ -1254,6 +1257,15 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
12541257
struct ref **heads = NULL;
12551258
struct ref *rm;
12561259

1260+
if (!transport->vtable->fetch_without_list)
1261+
/*
1262+
* Some transports (e.g. the built-in bundle transport and the
1263+
* transport helper interface) do not work when fetching is
1264+
* done immediately after transport creation. List the remote
1265+
* refs anyway (if not already listed) as a workaround.
1266+
*/
1267+
transport_get_remote_refs(transport, NULL);
1268+
12571269
for (rm = refs; rm; rm = rm->next) {
12581270
nr_refs++;
12591271
if (rm->peer_ref &&

0 commit comments

Comments
 (0)