connect, transport: encapsulate arg in struct
In a future patch we plan to return the name of an unborn current branch from deep in the callchain to a caller via a new pointer parameter that points at a variable in the caller when the caller calls get_remote_refs() and transport_get_remote_refs(). In preparation for that, encapsulate the existing ref_prefixes parameter into a struct. The aforementioned unborn current branch will go into this new struct in the future patch. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Feb 5, 2021 at 12:48 UTC
39835409d10de2402c4b3e10dba20286989627d4
10 files changed
+66
-49
builtin/clone.c
+11
-7
@@ -979,7 +979,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
979
int err = 0, complete_refs_before_fetch = 1;
980
int submodule_progress;
981
982
- struct strvec ref_prefixes = STRVEC_INIT;
982
+ struct transport_ls_refs_options transport_ls_refs_options =
983
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
984
985
packet_trace_identity("clone");
986
@@ -1257,14 +1258,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1258
transport->smart_options->check_self_contained_and_connected = 1;
1259
1260
1260
- strvec_push(&ref_prefixes, "HEAD");
1261
- refspec_ref_prefixes(&remote->fetch, &ref_prefixes);
1261
+ strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
1262
+ refspec_ref_prefixes(&remote->fetch,
1263
+ &transport_ls_refs_options.ref_prefixes);
1264
if (option_branch)
1263
- expand_ref_prefix(&ref_prefixes, option_branch);
1265
+ expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
1266
+ option_branch);
1267
if (!option_no_tags)
1265
- strvec_push(&ref_prefixes, "refs/tags/");
1268
+ strvec_push(&transport_ls_refs_options.ref_prefixes,
1269
+ "refs/tags/");
1270
1267
- refs = transport_get_remote_refs(transport, &ref_prefixes);
1271
+ refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
1272
1273
if (refs) {
1274
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
@@ -1380,6 +1384,6 @@ cleanup:
1384
strbuf_release(&key);
1385
junk_mode = JUNK_LEAVE_ALL;
1386
1383
- strvec_clear(&ref_prefixes);
1387
+ strvec_clear(&transport_ls_refs_options.ref_prefixes);
1388
return err;
1389
}
builtin/fetch-pack.c
+2
-1
@@ -220,7 +220,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
220
version = discover_version(&reader);
221
switch (version) {
222
case protocol_v2:
223
- get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL, args.stateless_rpc);
223
+ get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL,
224
+ args.stateless_rpc);
225
break;
226
case protocol_v1:
227
case protocol_v0:
builtin/fetch.c
+11
-7
@@ -1349,7 +1349,8 @@ static int do_fetch(struct transport *transport,
1349
int autotags = (transport->remote->fetch_tags == 1);
1350
int retcode = 0;
1351
const struct ref *remote_refs;
1352
- struct strvec ref_prefixes = STRVEC_INIT;
1352
+ struct transport_ls_refs_options transport_ls_refs_options =
1353
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
1354
int must_list_refs = 1;
1355
1356
if (tags == TAGS_DEFAULT) {
@@ -1369,7 +1370,7 @@ static int do_fetch(struct transport *transport,
1370
if (rs->nr) {
1371
int i;
1372
1372
- refspec_ref_prefixes(rs, &ref_prefixes);
1373
+ refspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes);
1374
1375
/*
1376
* We can avoid listing refs if all of them are exact
@@ -1383,22 +1384,25 @@ static int do_fetch(struct transport *transport,
1384
}
1385
}
1386
} else if (transport->remote && transport->remote->fetch.nr)
1386
- refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
1387
+ refspec_ref_prefixes(&transport->remote->fetch,
1388
+ &transport_ls_refs_options.ref_prefixes);
1389
1390
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
1391
must_list_refs = 1;
1390
- if (ref_prefixes.nr)
1391
- strvec_push(&ref_prefixes, "refs/tags/");
1392
+ if (transport_ls_refs_options.ref_prefixes.nr)
1393
+ strvec_push(&transport_ls_refs_options.ref_prefixes,
1394
+ "refs/tags/");
1395
}
1396
1397
if (must_list_refs) {
1398
trace2_region_enter("fetch", "remote_refs", the_repository);
1396
- remote_refs = transport_get_remote_refs(transport, &ref_prefixes);
1399
+ remote_refs = transport_get_remote_refs(transport,
1400
+ &transport_ls_refs_options);
1401
trace2_region_leave("fetch", "remote_refs", the_repository);
1402
} else
1403
remote_refs = NULL;
1404
1401
- strvec_clear(&ref_prefixes);
1405
+ strvec_clear(&transport_ls_refs_options.ref_prefixes);
1406
1407
ref_map = get_ref_map(transport->remote, remote_refs, rs,
1408
tags, &autotags);
builtin/ls-remote.c
+5
-4
@@ -45,7 +45,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
45
int show_symref_target = 0;
46
const char *uploadpack = NULL;
47
const char **pattern = NULL;
48
- struct strvec ref_prefixes = STRVEC_INIT;
48
+ struct transport_ls_refs_options transport_options =
49
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
50
int i;
51
struct string_list server_options = STRING_LIST_INIT_DUP;
52
@@ -94,9 +95,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
95
}
96
97
if (flags & REF_TAGS)
97
- strvec_push(&ref_prefixes, "refs/tags/");
98
+ strvec_push(&transport_options.ref_prefixes, "refs/tags/");
99
if (flags & REF_HEADS)
99
- strvec_push(&ref_prefixes, "refs/heads/");
100
+ strvec_push(&transport_options.ref_prefixes, "refs/heads/");
101
102
remote = remote_get(dest);
103
if (!remote) {
@@ -118,7 +119,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
119
if (server_options.nr)
120
transport->server_options = &server_options;
121
121
- ref = transport_get_remote_refs(transport, &ref_prefixes);
122
+ ref = transport_get_remote_refs(transport, &transport_options);
123
if (ref) {
124
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
125
repo_set_hash_algo(the_repository, hash_algo);
connect.c
+3
-1
@@ -453,12 +453,14 @@ void check_stateless_delimiter(int stateless_rpc,
453
454
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
455
struct ref **list, int for_push,
456
- const struct strvec *ref_prefixes,
456
+ struct transport_ls_refs_options *transport_options,
457
const struct string_list *server_options,
458
int stateless_rpc)
459
{
460
int i;
461
const char *hash_name;
462
+ struct strvec *ref_prefixes = transport_options ?
463
+ &transport_options->ref_prefixes : NULL;
464
*list = NULL;
465
466
if (server_supports_v2("ls-refs", 1))
remote.h
+3
-1
@@ -6,6 +6,8 @@
6
#include "hashmap.h"
7
#include "refspec.h"
8
9
+struct transport_ls_refs_options;
10
+
11
/**
12
* The API gives access to the configuration related to remotes. It handles
13
* all three configuration mechanisms historically and currently used by Git,
@@ -196,7 +198,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
198
/* Used for protocol v2 in order to retrieve refs from a remote */
199
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
200
struct ref **list, int for_push,
199
- const struct strvec *ref_prefixes,
201
+ struct transport_ls_refs_options *transport_options,
202
const struct string_list *server_options,
203
int stateless_rpc);
204
transport-helper.c
+3
-2
@@ -1162,13 +1162,14 @@ static int has_attribute(const char *attrs, const char *attr)
1162
}
1163
1164
static struct ref *get_refs_list(struct transport *transport, int for_push,
1165
- const struct strvec *ref_prefixes)
1165
+ struct transport_ls_refs_options *transport_options)
1166
{
1167
get_helper(transport);
1168
1169
if (process_connect(transport, for_push)) {
1170
do_take_over(transport);
1171
- return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
1171
+ return transport->vtable->get_refs_list(transport, for_push,
1172
+ transport_options);
1173
}
1174
1175
return get_refs_list_using_list(transport, for_push);
transport-internal.h
+2
-8
@@ -4,6 +4,7 @@
4
struct ref;
5
struct transport;
6
struct strvec;
7
+struct transport_ls_refs_options;
8
9
struct transport_vtable {
10
/**
@@ -18,19 +19,12 @@ struct transport_vtable {
19
* the transport to try to share connections, for_push is a
20
* hint as to whether the ultimate operation is a push or a fetch.
21
*
21
- * If communicating using protocol v2 a list of prefixes can be
22
- * provided to be sent to the server to enable it to limit the ref
23
- * advertisement. Since ref filtering is done on the server's end, and
24
- * only when using protocol v2, this list will be ignored when not
25
- * using protocol v2 meaning this function can return refs which don't
26
- * match the provided ref_prefixes.
27
- *
22
* If the transport is able to determine the remote hash for
23
* the ref without a huge amount of effort, it should store it
24
* in the ref's old_sha1 field; otherwise it should be all 0.
25
**/
26
struct ref *(*get_refs_list)(struct transport *transport, int for_push,
33
- const struct strvec *ref_prefixes);
27
+ struct transport_ls_refs_options *transport_options);
28
29
/**
30
* Fetch the objects for the given refs. Note that this gets
transport.c
+12
-11
@@ -127,7 +127,7 @@ struct bundle_transport_data {
127
128
static struct ref *get_refs_from_bundle(struct transport *transport,
129
int for_push,
130
- const struct strvec *ref_prefixes)
130
+ struct transport_ls_refs_options *transport_options)
131
{
132
struct bundle_transport_data *data = transport->data;
133
struct ref *result = NULL;
@@ -280,7 +280,7 @@ static void die_if_server_options(struct transport *transport)
280
* remote refs.
281
*/
282
static struct ref *handshake(struct transport *transport, int for_push,
283
- const struct strvec *ref_prefixes,
283
+ struct transport_ls_refs_options *options,
284
int must_list_refs)
285
{
286
struct git_transport_data *data = transport->data;
@@ -303,7 +303,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
303
trace2_data_string("transfer", NULL, "server-sid", server_sid);
304
if (must_list_refs)
305
get_remote_refs(data->fd[1], &reader, &refs, for_push,
306
- ref_prefixes,
306
+ options,
307
transport->server_options,
308
transport->stateless_rpc);
309
break;
@@ -334,9 +334,9 @@ static struct ref *handshake(struct transport *transport, int for_push,
334
}
335
336
static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
337
- const struct strvec *ref_prefixes)
337
+ struct transport_ls_refs_options *options)
338
{
339
- return handshake(transport, for_push, ref_prefixes, 1);
339
+ return handshake(transport, for_push, options, 1);
340
}
341
342
static int fetch_refs_via_pack(struct transport *transport,
@@ -1252,19 +1252,20 @@ int transport_push(struct repository *r,
1252
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
1253
int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
1254
int push_ret, ret, err;
1255
- struct strvec ref_prefixes = STRVEC_INIT;
1255
+ struct transport_ls_refs_options transport_options =
1256
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
1257
1258
if (check_push_refs(local_refs, rs) < 0)
1259
return -1;
1260
1260
- refspec_ref_prefixes(rs, &ref_prefixes);
1261
+ refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
1262
1263
trace2_region_enter("transport_push", "get_refs_list", r);
1264
remote_refs = transport->vtable->get_refs_list(transport, 1,
1264
- &ref_prefixes);
1265
+ &transport_options);
1266
trace2_region_leave("transport_push", "get_refs_list", r);
1267
1267
- strvec_clear(&ref_prefixes);
1268
+ strvec_clear(&transport_options.ref_prefixes);
1269
1270
if (flags & TRANSPORT_PUSH_ALL)
1271
match_flags |= MATCH_REFS_ALL;
@@ -1380,12 +1381,12 @@ int transport_push(struct repository *r,
1381
}
1382
1383
const struct ref *transport_get_remote_refs(struct transport *transport,
1383
- const struct strvec *ref_prefixes)
1384
+ struct transport_ls_refs_options *transport_options)
1385
{
1386
if (!transport->got_remote_refs) {
1387
transport->remote_refs =
1388
transport->vtable->get_refs_list(transport, 0,
1388
- ref_prefixes);
1389
+ transport_options);
1390
transport->got_remote_refs = 1;
1391
}
1392
transport.h
+14
-7
@@ -233,17 +233,24 @@ int transport_push(struct repository *repo,
233
struct refspec *rs, int flags,
234
unsigned int * reject_reasons);
235
236
+struct transport_ls_refs_options {
237
+ /*
238
+ * Optionally, a list of ref prefixes can be provided which can be sent
239
+ * to the server (when communicating using protocol v2) to enable it to
240
+ * limit the ref advertisement. Since ref filtering is done on the
241
+ * server's end (and only when using protocol v2),
242
+ * transport_get_remote_refs() could return refs which don't match the
243
+ * provided ref_prefixes.
244
+ */
245
+ struct strvec ref_prefixes;
246
+};
247
+#define TRANSPORT_LS_REFS_OPTIONS_INIT { STRVEC_INIT }
248
+
249
/*
250
* Retrieve refs from a remote.
238
- *
239
- * Optionally a list of ref prefixes can be provided which can be sent to the
240
- * server (when communicating using protocol v2) to enable it to limit the ref
241
- * advertisement. Since ref filtering is done on the server's end (and only
242
- * when using protocol v2), this can return refs which don't match the provided
243
- * ref_prefixes.
251
*/
252
const struct ref *transport_get_remote_refs(struct transport *transport,
246
- const struct strvec *ref_prefixes);
253
+ struct transport_ls_refs_options *transport_options);
254
255
/*
256
* Fetch the hash algorithm used by a remote.