Skip to content

Commit c5cbc64

Browse files
committed
fetch: make filter_options local to cmd_fetch()
The `struct list_objects_filter_options filter_options` variable used in "builtin/fetch.c" to store the parsed filters specified by `--filter=<filterspec>` is currently a static variable global to the file. As we are going to use it more in a following commit, it could become a bit less easy to understand how it's managed. To avoid that, let's make it clear that it's owned by cmd_fetch() by moving its definition into that function and making it non-static. This require passing a pointer to it through the prepare_transport(), do_fetch(), backfill_tags(), fetch_one_setup_partial(), and fetch_one() functions, but it's quite straightforward. Signed-off-by: Christian Couder <[email protected]>
1 parent 629b1ba commit c5cbc64

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

builtin/fetch.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ static struct strbuf default_rla = STRBUF_INIT;
9797
static struct transport *gtransport;
9898
static struct transport *gsecondary;
9999
static struct refspec refmap = REFSPEC_INIT_FETCH;
100-
static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
101100
static struct string_list server_options = STRING_LIST_INIT_DUP;
102101
static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
103102

@@ -1449,7 +1448,8 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
14491448
smart_options->negotiation_tips = oids;
14501449
}
14511450

1452-
static struct transport *prepare_transport(struct remote *remote, int deepen)
1451+
static struct transport *prepare_transport(struct remote *remote, int deepen,
1452+
struct list_objects_filter_options *filter_options)
14531453
{
14541454
struct transport *transport;
14551455

@@ -1473,9 +1473,9 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
14731473
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
14741474
if (refetch)
14751475
set_option(transport, TRANS_OPT_REFETCH, "yes");
1476-
if (filter_options.choice) {
1476+
if (filter_options->choice) {
14771477
const char *spec =
1478-
expand_list_objects_filter_spec(&filter_options);
1478+
expand_list_objects_filter_spec(filter_options);
14791479
set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, spec);
14801480
set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
14811481
}
@@ -1493,7 +1493,8 @@ static int backfill_tags(struct display_state *display_state,
14931493
struct ref_transaction *transaction,
14941494
struct ref *ref_map,
14951495
struct fetch_head *fetch_head,
1496-
const struct fetch_config *config)
1496+
const struct fetch_config *config,
1497+
struct list_objects_filter_options *filter_options)
14971498
{
14981499
int retcode, cannot_reuse;
14991500

@@ -1507,7 +1508,7 @@ static int backfill_tags(struct display_state *display_state,
15071508
cannot_reuse = transport->cannot_reuse ||
15081509
deepen_since || deepen_not.nr;
15091510
if (cannot_reuse) {
1510-
gsecondary = prepare_transport(transport->remote, 0);
1511+
gsecondary = prepare_transport(transport->remote, 0, filter_options);
15111512
transport = gsecondary;
15121513
}
15131514

@@ -1713,7 +1714,8 @@ static int commit_ref_transaction(struct ref_transaction **transaction,
17131714

17141715
static int do_fetch(struct transport *transport,
17151716
struct refspec *rs,
1716-
const struct fetch_config *config)
1717+
const struct fetch_config *config,
1718+
struct list_objects_filter_options *filter_options)
17171719
{
17181720
struct ref_transaction *transaction = NULL;
17191721
struct ref *ref_map = NULL;
@@ -1873,7 +1875,7 @@ static int do_fetch(struct transport *transport,
18731875
* the transaction and don't commit anything.
18741876
*/
18751877
if (backfill_tags(&display_state, transport, transaction, tags_ref_map,
1876-
&fetch_head, config))
1878+
&fetch_head, config, filter_options))
18771879
retcode = 1;
18781880
}
18791881

@@ -2198,20 +2200,21 @@ static int fetch_multiple(struct string_list *list, int max_children,
21982200
* Fetching from the promisor remote should use the given filter-spec
21992201
* or inherit the default filter-spec from the config.
22002202
*/
2201-
static inline void fetch_one_setup_partial(struct remote *remote)
2203+
static inline void fetch_one_setup_partial(struct remote *remote,
2204+
struct list_objects_filter_options *filter_options)
22022205
{
22032206
/*
22042207
* Explicit --no-filter argument overrides everything, regardless
22052208
* of any prior partial clones and fetches.
22062209
*/
2207-
if (filter_options.no_filter)
2210+
if (filter_options->no_filter)
22082211
return;
22092212

22102213
/*
22112214
* If no prior partial clone/fetch and the current fetch DID NOT
22122215
* request a partial-fetch, do a normal fetch.
22132216
*/
2214-
if (!repo_has_promisor_remote(the_repository) && !filter_options.choice)
2217+
if (!repo_has_promisor_remote(the_repository) && !filter_options->choice)
22152218
return;
22162219

22172220
/*
@@ -2220,8 +2223,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
22202223
* filter-spec as the default for subsequent fetches to this
22212224
* remote if there is currently no default filter-spec.
22222225
*/
2223-
if (filter_options.choice) {
2224-
partial_clone_register(remote->name, &filter_options);
2226+
if (filter_options->choice) {
2227+
partial_clone_register(remote->name, filter_options);
22252228
return;
22262229
}
22272230

@@ -2230,14 +2233,15 @@ static inline void fetch_one_setup_partial(struct remote *remote)
22302233
* explicitly given filter-spec or inherit the filter-spec from
22312234
* the config.
22322235
*/
2233-
if (!filter_options.choice)
2234-
partial_clone_get_default_filter_spec(&filter_options, remote->name);
2236+
if (!filter_options->choice)
2237+
partial_clone_get_default_filter_spec(filter_options, remote->name);
22352238
return;
22362239
}
22372240

22382241
static int fetch_one(struct remote *remote, int argc, const char **argv,
22392242
int prune_tags_ok, int use_stdin_refspecs,
2240-
const struct fetch_config *config)
2243+
const struct fetch_config *config,
2244+
struct list_objects_filter_options *filter_options)
22412245
{
22422246
struct refspec rs = REFSPEC_INIT_FETCH;
22432247
int i;
@@ -2249,7 +2253,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
22492253
die(_("no remote repository specified; please specify either a URL or a\n"
22502254
"remote name from which new revisions should be fetched"));
22512255

2252-
gtransport = prepare_transport(remote, 1);
2256+
gtransport = prepare_transport(remote, 1, filter_options);
22532257

22542258
if (prune < 0) {
22552259
/* no command line request */
@@ -2304,7 +2308,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
23042308
sigchain_push_common(unlock_pack_on_signal);
23052309
atexit(unlock_pack_atexit);
23062310
sigchain_push(SIGPIPE, SIG_IGN);
2307-
exit_code = do_fetch(gtransport, &rs, config);
2311+
exit_code = do_fetch(gtransport, &rs, config, filter_options);
23082312
sigchain_pop(SIGPIPE);
23092313
refspec_clear(&rs);
23102314
transport_disconnect(gtransport);
@@ -2329,6 +2333,7 @@ int cmd_fetch(int argc,
23292333
const char *submodule_prefix = "";
23302334
const char *bundle_uri;
23312335
struct string_list list = STRING_LIST_INIT_DUP;
2336+
struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
23322337
struct remote *remote = NULL;
23332338
int all = -1, multiple = 0;
23342339
int result = 0;
@@ -2594,7 +2599,7 @@ int cmd_fetch(int argc,
25942599
trace2_region_enter("fetch", "negotiate-only", the_repository);
25952600
if (!remote)
25962601
die(_("must supply remote when using --negotiate-only"));
2597-
gtransport = prepare_transport(remote, 1);
2602+
gtransport = prepare_transport(remote, 1, &filter_options);
25982603
if (gtransport->smart_options) {
25992604
gtransport->smart_options->acked_commits = &acked_commits;
26002605
} else {
@@ -2616,12 +2621,12 @@ int cmd_fetch(int argc,
26162621
} else if (remote) {
26172622
if (filter_options.choice || repo_has_promisor_remote(the_repository)) {
26182623
trace2_region_enter("fetch", "setup-partial", the_repository);
2619-
fetch_one_setup_partial(remote);
2624+
fetch_one_setup_partial(remote, &filter_options);
26202625
trace2_region_leave("fetch", "setup-partial", the_repository);
26212626
}
26222627
trace2_region_enter("fetch", "fetch-one", the_repository);
26232628
result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs,
2624-
&config);
2629+
&config, &filter_options);
26252630
trace2_region_leave("fetch", "fetch-one", the_repository);
26262631
} else {
26272632
int max_children = max_jobs;
@@ -2727,5 +2732,6 @@ int cmd_fetch(int argc,
27272732

27282733
cleanup:
27292734
string_list_clear(&list, 0);
2735+
list_objects_filter_release(&filter_options);
27302736
return result;
27312737
}

0 commit comments

Comments
 (0)