Skip to content

Commit ba28b2c

Browse files
pks-tgitster
authored andcommitted
fetch: use fetch_config to store "fetch.showForcedUpdates" value
Move the parsed "fetch.showForcedUpdaets" config value into the `fetch_config` structure. This reduces our reliance on global variables and further unifies the way we parse the configuration in git-fetch(1). Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b472cf commit ba28b2c

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

builtin/fetch.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct display_state {
7373
int url_len, shown_url;
7474
};
7575

76-
static int fetch_show_forced_updates = 1;
7776
static uint64_t forced_updates_ms = 0;
7877
static int prefetch = 0;
7978
static int prune = -1; /* unspecified */
@@ -108,6 +107,7 @@ struct fetch_config {
108107
enum display_format display_format;
109108
int prune;
110109
int prune_tags;
110+
int show_forced_updates;
111111
};
112112

113113
static int git_fetch_config(const char *k, const char *v, void *cb)
@@ -125,7 +125,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
125125
}
126126

127127
if (!strcmp(k, "fetch.showforcedupdates")) {
128-
fetch_show_forced_updates = git_config_bool(k, v);
128+
fetch_config->show_forced_updates = git_config_bool(k, v);
129129
return 0;
130130
}
131131

@@ -891,7 +891,8 @@ static int update_local_ref(struct ref *ref,
891891
struct ref_transaction *transaction,
892892
struct display_state *display_state,
893893
const struct ref *remote_ref,
894-
int summary_width)
894+
int summary_width,
895+
const struct fetch_config *config)
895896
{
896897
struct commit *current = NULL, *updated;
897898
int fast_forward = 0;
@@ -972,7 +973,7 @@ static int update_local_ref(struct ref *ref,
972973
return r;
973974
}
974975

975-
if (fetch_show_forced_updates) {
976+
if (config->show_forced_updates) {
976977
uint64_t t_before = getnanotime();
977978
fast_forward = repo_in_merge_bases(the_repository, current,
978979
updated);
@@ -1125,7 +1126,8 @@ static int store_updated_refs(struct display_state *display_state,
11251126
const char *remote_name,
11261127
int connectivity_checked,
11271128
struct ref_transaction *transaction, struct ref *ref_map,
1128-
struct fetch_head *fetch_head)
1129+
struct fetch_head *fetch_head,
1130+
const struct fetch_config *config)
11291131
{
11301132
int rc = 0;
11311133
struct strbuf note = STRBUF_INIT;
@@ -1241,7 +1243,7 @@ static int store_updated_refs(struct display_state *display_state,
12411243

12421244
if (ref) {
12431245
rc |= update_local_ref(ref, transaction, display_state,
1244-
rm, summary_width);
1246+
rm, summary_width, config);
12451247
free(ref);
12461248
} else if (write_fetch_head || dry_run) {
12471249
/*
@@ -1265,7 +1267,7 @@ static int store_updated_refs(struct display_state *display_state,
12651267
"branches"), remote_name);
12661268

12671269
if (advice_enabled(ADVICE_FETCH_SHOW_FORCED_UPDATES)) {
1268-
if (!fetch_show_forced_updates) {
1270+
if (!config->show_forced_updates) {
12691271
warning(_(warn_show_forced_updates));
12701272
} else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
12711273
warning(_(warn_time_show_forced_updates),
@@ -1326,7 +1328,8 @@ static int fetch_and_consume_refs(struct display_state *display_state,
13261328
struct transport *transport,
13271329
struct ref_transaction *transaction,
13281330
struct ref *ref_map,
1329-
struct fetch_head *fetch_head)
1331+
struct fetch_head *fetch_head,
1332+
const struct fetch_config *config)
13301333
{
13311334
int connectivity_checked = 1;
13321335
int ret;
@@ -1349,7 +1352,7 @@ static int fetch_and_consume_refs(struct display_state *display_state,
13491352
trace2_region_enter("fetch", "consume_refs", the_repository);
13501353
ret = store_updated_refs(display_state, transport->remote->name,
13511354
connectivity_checked, transaction, ref_map,
1352-
fetch_head);
1355+
fetch_head, config);
13531356
trace2_region_leave("fetch", "consume_refs", the_repository);
13541357

13551358
out:
@@ -1520,7 +1523,8 @@ static int backfill_tags(struct display_state *display_state,
15201523
struct transport *transport,
15211524
struct ref_transaction *transaction,
15221525
struct ref *ref_map,
1523-
struct fetch_head *fetch_head)
1526+
struct fetch_head *fetch_head,
1527+
const struct fetch_config *config)
15241528
{
15251529
int retcode, cannot_reuse;
15261530

@@ -1541,7 +1545,8 @@ static int backfill_tags(struct display_state *display_state,
15411545
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
15421546
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
15431547
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
1544-
retcode = fetch_and_consume_refs(display_state, transport, transaction, ref_map, fetch_head);
1548+
retcode = fetch_and_consume_refs(display_state, transport, transaction, ref_map,
1549+
fetch_head, config);
15451550

15461551
if (gsecondary) {
15471552
transport_disconnect(gsecondary);
@@ -1668,7 +1673,8 @@ static int do_fetch(struct transport *transport,
16681673
retcode = 1;
16691674
}
16701675

1671-
if (fetch_and_consume_refs(&display_state, transport, transaction, ref_map, &fetch_head)) {
1676+
if (fetch_and_consume_refs(&display_state, transport, transaction, ref_map,
1677+
&fetch_head, config)) {
16721678
retcode = 1;
16731679
goto cleanup;
16741680
}
@@ -1691,7 +1697,7 @@ static int do_fetch(struct transport *transport,
16911697
* the transaction and don't commit anything.
16921698
*/
16931699
if (backfill_tags(&display_state, transport, transaction, tags_ref_map,
1694-
&fetch_head))
1700+
&fetch_head, config))
16951701
retcode = 1;
16961702
}
16971703

@@ -2110,6 +2116,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
21102116
.display_format = DISPLAY_FORMAT_FULL,
21112117
.prune = -1,
21122118
.prune_tags = -1,
2119+
.show_forced_updates = 1,
21132120
};
21142121
const char *submodule_prefix = "";
21152122
const char *bundle_uri;
@@ -2207,7 +2214,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
22072214
N_("run 'maintenance --auto' after fetching")),
22082215
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
22092216
N_("run 'maintenance --auto' after fetching")),
2210-
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
2217+
OPT_BOOL(0, "show-forced-updates", &config.show_forced_updates,
22112218
N_("check for forced-updates on all updated branches")),
22122219
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
22132220
N_("write the commit-graph after fetching")),

0 commit comments

Comments
 (0)