Skip to content

Commit 3983540

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

File tree

10 files changed

+66
-49
lines changed

10 files changed

+66
-49
lines changed

builtin/clone.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
979979
int err = 0, complete_refs_before_fetch = 1;
980980
int submodule_progress;
981981

982-
struct strvec ref_prefixes = STRVEC_INIT;
982+
struct transport_ls_refs_options transport_ls_refs_options =
983+
TRANSPORT_LS_REFS_OPTIONS_INIT;
983984

984985
packet_trace_identity("clone");
985986

@@ -1257,14 +1258,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12571258
transport->smart_options->check_self_contained_and_connected = 1;
12581259

12591260

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);
12621264
if (option_branch)
1263-
expand_ref_prefix(&ref_prefixes, option_branch);
1265+
expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
1266+
option_branch);
12641267
if (!option_no_tags)
1265-
strvec_push(&ref_prefixes, "refs/tags/");
1268+
strvec_push(&transport_ls_refs_options.ref_prefixes,
1269+
"refs/tags/");
12661270

1267-
refs = transport_get_remote_refs(transport, &ref_prefixes);
1271+
refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
12681272

12691273
if (refs) {
12701274
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
@@ -1380,6 +1384,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13801384
strbuf_release(&key);
13811385
junk_mode = JUNK_LEAVE_ALL;
13821386

1383-
strvec_clear(&ref_prefixes);
1387+
strvec_clear(&transport_ls_refs_options.ref_prefixes);
13841388
return err;
13851389
}

builtin/fetch-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
220220
version = discover_version(&reader);
221221
switch (version) {
222222
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);
224225
break;
225226
case protocol_v1:
226227
case protocol_v0:

builtin/fetch.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,8 @@ static int do_fetch(struct transport *transport,
13491349
int autotags = (transport->remote->fetch_tags == 1);
13501350
int retcode = 0;
13511351
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;
13531354
int must_list_refs = 1;
13541355

13551356
if (tags == TAGS_DEFAULT) {
@@ -1369,7 +1370,7 @@ static int do_fetch(struct transport *transport,
13691370
if (rs->nr) {
13701371
int i;
13711372

1372-
refspec_ref_prefixes(rs, &ref_prefixes);
1373+
refspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes);
13731374

13741375
/*
13751376
* We can avoid listing refs if all of them are exact
@@ -1383,22 +1384,25 @@ static int do_fetch(struct transport *transport,
13831384
}
13841385
}
13851386
} 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);
13871389

13881390
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
13891391
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/");
13921395
}
13931396

13941397
if (must_list_refs) {
13951398
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);
13971401
trace2_region_leave("fetch", "remote_refs", the_repository);
13981402
} else
13991403
remote_refs = NULL;
14001404

1401-
strvec_clear(&ref_prefixes);
1405+
strvec_clear(&transport_ls_refs_options.ref_prefixes);
14021406

14031407
ref_map = get_ref_map(transport->remote, remote_refs, rs,
14041408
tags, &autotags);

builtin/ls-remote.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
4545
int show_symref_target = 0;
4646
const char *uploadpack = NULL;
4747
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;
4950
int i;
5051
struct string_list server_options = STRING_LIST_INIT_DUP;
5152

@@ -94,9 +95,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9495
}
9596

9697
if (flags & REF_TAGS)
97-
strvec_push(&ref_prefixes, "refs/tags/");
98+
strvec_push(&transport_options.ref_prefixes, "refs/tags/");
9899
if (flags & REF_HEADS)
99-
strvec_push(&ref_prefixes, "refs/heads/");
100+
strvec_push(&transport_options.ref_prefixes, "refs/heads/");
100101

101102
remote = remote_get(dest);
102103
if (!remote) {
@@ -118,7 +119,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
118119
if (server_options.nr)
119120
transport->server_options = &server_options;
120121

121-
ref = transport_get_remote_refs(transport, &ref_prefixes);
122+
ref = transport_get_remote_refs(transport, &transport_options);
122123
if (ref) {
123124
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
124125
repo_set_hash_algo(the_repository, hash_algo);

connect.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,14 @@ void check_stateless_delimiter(int stateless_rpc,
453453

454454
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
455455
struct ref **list, int for_push,
456-
const struct strvec *ref_prefixes,
456+
struct transport_ls_refs_options *transport_options,
457457
const struct string_list *server_options,
458458
int stateless_rpc)
459459
{
460460
int i;
461461
const char *hash_name;
462+
struct strvec *ref_prefixes = transport_options ?
463+
&transport_options->ref_prefixes : NULL;
462464
*list = NULL;
463465

464466
if (server_supports_v2("ls-refs", 1))

remote.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "hashmap.h"
77
#include "refspec.h"
88

9+
struct transport_ls_refs_options;
10+
911
/**
1012
* The API gives access to the configuration related to remotes. It handles
1113
* all three configuration mechanisms historically and currently used by Git,
@@ -196,7 +198,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
196198
/* Used for protocol v2 in order to retrieve refs from a remote */
197199
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
198200
struct ref **list, int for_push,
199-
const struct strvec *ref_prefixes,
201+
struct transport_ls_refs_options *transport_options,
200202
const struct string_list *server_options,
201203
int stateless_rpc);
202204

transport-helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,13 +1162,14 @@ static int has_attribute(const char *attrs, const char *attr)
11621162
}
11631163

11641164
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)
11661166
{
11671167
get_helper(transport);
11681168

11691169
if (process_connect(transport, for_push)) {
11701170
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);
11721173
}
11731174

11741175
return get_refs_list_using_list(transport, for_push);

transport-internal.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct ref;
55
struct transport;
66
struct strvec;
7+
struct transport_ls_refs_options;
78

89
struct transport_vtable {
910
/**
@@ -18,19 +19,12 @@ struct transport_vtable {
1819
* the transport to try to share connections, for_push is a
1920
* hint as to whether the ultimate operation is a push or a fetch.
2021
*
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-
*
2822
* If the transport is able to determine the remote hash for
2923
* the ref without a huge amount of effort, it should store it
3024
* in the ref's old_sha1 field; otherwise it should be all 0.
3125
**/
3226
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);
3428

3529
/**
3630
* Fetch the objects for the given refs. Note that this gets

transport.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct bundle_transport_data {
127127

128128
static struct ref *get_refs_from_bundle(struct transport *transport,
129129
int for_push,
130-
const struct strvec *ref_prefixes)
130+
struct transport_ls_refs_options *transport_options)
131131
{
132132
struct bundle_transport_data *data = transport->data;
133133
struct ref *result = NULL;
@@ -280,7 +280,7 @@ static void die_if_server_options(struct transport *transport)
280280
* remote refs.
281281
*/
282282
static struct ref *handshake(struct transport *transport, int for_push,
283-
const struct strvec *ref_prefixes,
283+
struct transport_ls_refs_options *options,
284284
int must_list_refs)
285285
{
286286
struct git_transport_data *data = transport->data;
@@ -303,7 +303,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
303303
trace2_data_string("transfer", NULL, "server-sid", server_sid);
304304
if (must_list_refs)
305305
get_remote_refs(data->fd[1], &reader, &refs, for_push,
306-
ref_prefixes,
306+
options,
307307
transport->server_options,
308308
transport->stateless_rpc);
309309
break;
@@ -334,9 +334,9 @@ static struct ref *handshake(struct transport *transport, int for_push,
334334
}
335335

336336
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)
338338
{
339-
return handshake(transport, for_push, ref_prefixes, 1);
339+
return handshake(transport, for_push, options, 1);
340340
}
341341

342342
static int fetch_refs_via_pack(struct transport *transport,
@@ -1252,19 +1252,20 @@ int transport_push(struct repository *r,
12521252
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
12531253
int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
12541254
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;
12561257

12571258
if (check_push_refs(local_refs, rs) < 0)
12581259
return -1;
12591260

1260-
refspec_ref_prefixes(rs, &ref_prefixes);
1261+
refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
12611262

12621263
trace2_region_enter("transport_push", "get_refs_list", r);
12631264
remote_refs = transport->vtable->get_refs_list(transport, 1,
1264-
&ref_prefixes);
1265+
&transport_options);
12651266
trace2_region_leave("transport_push", "get_refs_list", r);
12661267

1267-
strvec_clear(&ref_prefixes);
1268+
strvec_clear(&transport_options.ref_prefixes);
12681269

12691270
if (flags & TRANSPORT_PUSH_ALL)
12701271
match_flags |= MATCH_REFS_ALL;
@@ -1380,12 +1381,12 @@ int transport_push(struct repository *r,
13801381
}
13811382

13821383
const struct ref *transport_get_remote_refs(struct transport *transport,
1383-
const struct strvec *ref_prefixes)
1384+
struct transport_ls_refs_options *transport_options)
13841385
{
13851386
if (!transport->got_remote_refs) {
13861387
transport->remote_refs =
13871388
transport->vtable->get_refs_list(transport, 0,
1388-
ref_prefixes);
1389+
transport_options);
13891390
transport->got_remote_refs = 1;
13901391
}
13911392

transport.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,24 @@ int transport_push(struct repository *repo,
233233
struct refspec *rs, int flags,
234234
unsigned int * reject_reasons);
235235

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+
236249
/*
237250
* 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.
244251
*/
245252
const struct ref *transport_get_remote_refs(struct transport *transport,
246-
const struct strvec *ref_prefixes);
253+
struct transport_ls_refs_options *transport_options);
247254

248255
/*
249256
* Fetch the hash algorithm used by a remote.

0 commit comments

Comments
 (0)