Skip to content

Commit fddf2eb

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac3fda8 commit fddf2eb

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

t/t5607-clone-bundle.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ test_expect_success 'failed bundle creation does not leave cruft' '
8383
test_path_is_missing fail.bundle.lock
8484
'
8585

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+
8697
test_done

transport-helper.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
11461146
}
11471147

11481148
static struct transport_vtable vtable = {
1149-
1,
11501149
set_helper_option,
11511150
get_refs_list,
11521151
fetch,

transport-internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ 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-
159
/**
1610
* Returns 0 if successful, positive if the option is not
1711
* recognized or is inapplicable, and negative if the option

transport.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
122122
struct bundle_transport_data {
123123
int fd;
124124
struct bundle_header header;
125+
unsigned get_refs_from_bundle_called : 1;
125126
};
126127

127128
static struct ref *get_refs_from_bundle(struct transport *transport,
@@ -135,6 +136,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
135136
if (for_push)
136137
return NULL;
137138

139+
data->get_refs_from_bundle_called = 1;
140+
138141
if (data->fd > 0)
139142
close(data->fd);
140143
data->fd = read_bundle_header(transport->url, &data->header);
@@ -154,6 +157,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
154157
int nr_heads, struct ref **to_fetch)
155158
{
156159
struct bundle_transport_data *data = transport->data;
160+
161+
if (!data->get_refs_from_bundle_called)
162+
get_refs_from_bundle(transport, 0, NULL);
157163
return unbundle(the_repository, &data->header, data->fd,
158164
transport->progress ? BUNDLE_VERBOSE : 0);
159165
}
@@ -742,7 +748,6 @@ static int disconnect_git(struct transport *transport)
742748
}
743749

744750
static struct transport_vtable taken_over_vtable = {
745-
1,
746751
NULL,
747752
get_refs_via_connect,
748753
fetch_refs_via_pack,
@@ -892,7 +897,6 @@ void transport_check_allowed(const char *type)
892897
}
893898

894899
static struct transport_vtable bundle_vtable = {
895-
0,
896900
NULL,
897901
get_refs_from_bundle,
898902
fetch_refs_from_bundle,
@@ -902,7 +906,6 @@ static struct transport_vtable bundle_vtable = {
902906
};
903907

904908
static struct transport_vtable builtin_smart_vtable = {
905-
1,
906909
NULL,
907910
get_refs_via_connect,
908911
fetch_refs_via_pack,
@@ -1285,15 +1288,6 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
12851288
struct ref **heads = NULL;
12861289
struct ref *rm;
12871290

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-
12971291
for (rm = refs; rm; rm = rm->next) {
12981292
nr_refs++;
12991293
if (rm->peer_ref &&

0 commit comments

Comments
 (0)