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 <gitster@pobox.com>
Jonathan Tan committed
Sep 27, 2018 at 12:24 UTC
99bcb883cb2bd2d27939a831a66d794770427e98
1 file changed
+25
-4
transport.c
+25
-4
@@ -252,8 +252,18 @@ static int connect_setup(struct transport *transport, int for_push)
252
return 0;
253
}
254
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)
267
{
268
struct git_transport_data *data = transport->data;
269
struct ref *refs = NULL;
@@ -268,8 +278,10 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
278
data->version = discover_version(&reader);
279
switch (data->version) {
280
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);
285
break;
286
case protocol_v1:
287
case protocol_v0:
@@ -283,9 +295,18 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
295
}
296
data->got_remote_heads = 1;
297
298
+ if (reader.line_peeked)
299
+ BUG("buffer must be empty at the end of handshake()");
300
+
301
return refs;
302
}
303
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
+
310
static int fetch_refs_via_pack(struct transport *transport,
311
int nr_heads, struct ref **to_fetch)
312
{