transport: teach all vtables to allow fetch first
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>
Jonathan Tan committed
Aug 21, 2019 at 15:20 UTC
fddf2ebe388f3a11013c14ebe012dee520caa9ff
4 files changed
+17
-19
t/t5607-clone-bundle.sh
+11
@@ -83,4 +83,15 @@ test_expect_success 'failed bundle creation does not leave cruft' '
83
test_path_is_missing fail.bundle.lock
84
'
85
86
+test_expect_success 'fetch SHA-1 from bundle' '
87
+ test_create_repo foo &&
88
+ test_commit -C foo x &&
89
+ git -C foo bundle create tip.bundle -1 master &&
90
+ git -C foo rev-parse HEAD >hash &&
91
+
92
+ # Exercise to ensure that fetching a SHA-1 from a bundle works with no
93
+ # errors
94
+ git fetch --no-tags foo/tip.bundle "$(cat hash)"
95
+'
96
+
97
test_done
transport-helper.c
-1
@@ -1146,7 +1146,6 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
1146
}
1147
1148
static struct transport_vtable vtable = {
1149
- 1,
1149
set_helper_option,
1150
get_refs_list,
1151
fetch,
transport-internal.h
-6
@@ -6,12 +6,6 @@ struct transport;
6
struct argv_array;
7
8
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
-
9
/**
10
* Returns 0 if successful, positive if the option is not
11
* recognized or is inapplicable, and negative if the option
transport.c
+6
-12
@@ -122,6 +122,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
122
struct bundle_transport_data {
123
int fd;
124
struct bundle_header header;
125
+ unsigned get_refs_from_bundle_called : 1;
126
};
127
128
static struct ref *get_refs_from_bundle(struct transport *transport,
@@ -135,6 +136,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
136
if (for_push)
137
return NULL;
138
139
+ data->get_refs_from_bundle_called = 1;
140
+
141
if (data->fd > 0)
142
close(data->fd);
143
data->fd = read_bundle_header(transport->url, &data->header);
@@ -154,6 +157,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
157
int nr_heads, struct ref **to_fetch)
158
{
159
struct bundle_transport_data *data = transport->data;
160
+
161
+ if (!data->get_refs_from_bundle_called)
162
+ get_refs_from_bundle(transport, 0, NULL);
163
return unbundle(the_repository, &data->header, data->fd,
164
transport->progress ? BUNDLE_VERBOSE : 0);
165
}
@@ -742,7 +748,6 @@ static int disconnect_git(struct transport *transport)
748
}
749
750
static struct transport_vtable taken_over_vtable = {
745
- 1,
751
NULL,
752
get_refs_via_connect,
753
fetch_refs_via_pack,
@@ -892,7 +897,6 @@ void transport_check_allowed(const char *type)
897
}
898
899
static struct transport_vtable bundle_vtable = {
895
- 0,
900
NULL,
901
get_refs_from_bundle,
902
fetch_refs_from_bundle,
@@ -902,7 +906,6 @@ static struct transport_vtable bundle_vtable = {
906
};
907
908
static struct transport_vtable builtin_smart_vtable = {
905
- 1,
909
NULL,
910
get_refs_via_connect,
911
fetch_refs_via_pack,
@@ -1285,15 +1288,6 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
1288
struct ref **heads = NULL;
1289
struct ref *rm;
1290
1288
- if (!transport->vtable->fetch_without_list)
1289
- /*
1290
- * Some transports (e.g. the built-in bundle transport and the
1291
- * transport helper interface) do not work when fetching is
1292
- * done immediately after transport creation. List the remote
1293
- * refs anyway (if not already listed) as a workaround.
1294
- */
1295
- transport_get_remote_refs(transport, NULL);
1296
-
1291
for (rm = refs; rm; rm = rm->next) {
1292
nr_refs++;
1293
if (rm->peer_ref &&