Skip to content

Commit 99bcb88

Browse files
jonathantanmygitster
authored andcommitted
transport: allow skipping of ref listing
The get_refs_via_connect() function both performs the handshake (including determining the protocol version) and obtaining the list of remote refs. However, the fetch protocol v2 supports fetching objects without the listing of refs, so make it possible for the user to skip the listing by creating a new handshake() function. This will be used in a subsequent commit. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f84b9b0 commit 99bcb88

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

transport.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,18 @@ static int connect_setup(struct transport *transport, int for_push)
252252
return 0;
253253
}
254254

255-
static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
256-
const struct argv_array *ref_prefixes)
255+
/*
256+
* Obtains the protocol version from the transport and writes it to
257+
* transport->data->version, first connecting if not already connected.
258+
*
259+
* If the protocol version is one that allows skipping the listing of remote
260+
* refs, and must_list_refs is 0, the listing of remote refs is skipped and
261+
* this function returns NULL. Otherwise, this function returns the list of
262+
* remote refs.
263+
*/
264+
static struct ref *handshake(struct transport *transport, int for_push,
265+
const struct argv_array *ref_prefixes,
266+
int must_list_refs)
257267
{
258268
struct git_transport_data *data = transport->data;
259269
struct ref *refs = NULL;
@@ -268,8 +278,10 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
268278
data->version = discover_version(&reader);
269279
switch (data->version) {
270280
case protocol_v2:
271-
get_remote_refs(data->fd[1], &reader, &refs, for_push,
272-
ref_prefixes, transport->server_options);
281+
if (must_list_refs)
282+
get_remote_refs(data->fd[1], &reader, &refs, for_push,
283+
ref_prefixes,
284+
transport->server_options);
273285
break;
274286
case protocol_v1:
275287
case protocol_v0:
@@ -283,9 +295,18 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
283295
}
284296
data->got_remote_heads = 1;
285297

298+
if (reader.line_peeked)
299+
BUG("buffer must be empty at the end of handshake()");
300+
286301
return refs;
287302
}
288303

304+
static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
305+
const struct argv_array *ref_prefixes)
306+
{
307+
return handshake(transport, for_push, ref_prefixes, 1);
308+
}
309+
289310
static int fetch_refs_via_pack(struct transport *transport,
290311
int nr_heads, struct ref **to_fetch)
291312
{

0 commit comments

Comments
 (0)