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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
May 17, 2023 at 13:49 UTC
ba28b2ca5dcefb54689d0c442999b74af619f898
1 file changed
+21
-14
builtin/fetch.c
+21
-14
@@ -73,7 +73,6 @@ struct display_state {
73
int url_len, shown_url;
74
};
75
76
-static int fetch_show_forced_updates = 1;
76
static uint64_t forced_updates_ms = 0;
77
static int prefetch = 0;
78
static int prune = -1; /* unspecified */
@@ -108,6 +107,7 @@ struct fetch_config {
107
enum display_format display_format;
108
int prune;
109
int prune_tags;
110
+ int show_forced_updates;
111
};
112
113
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)
125
}
126
127
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);
129
return 0;
130
}
131
@@ -891,7 +891,8 @@ static int update_local_ref(struct ref *ref,
891
struct ref_transaction *transaction,
892
struct display_state *display_state,
893
const struct ref *remote_ref,
894
- int summary_width)
894
+ int summary_width,
895
+ const struct fetch_config *config)
896
{
897
struct commit *current = NULL, *updated;
898
int fast_forward = 0;
@@ -972,7 +973,7 @@ static int update_local_ref(struct ref *ref,
973
return r;
974
}
975
975
- if (fetch_show_forced_updates) {
976
+ if (config->show_forced_updates) {
977
uint64_t t_before = getnanotime();
978
fast_forward = repo_in_merge_bases(the_repository, current,
979
updated);
@@ -1125,7 +1126,8 @@ static int store_updated_refs(struct display_state *display_state,
1126
const char *remote_name,
1127
int connectivity_checked,
1128
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)
1131
{
1132
int rc = 0;
1133
struct strbuf note = STRBUF_INIT;
@@ -1241,7 +1243,7 @@ static int store_updated_refs(struct display_state *display_state,
1243
1244
if (ref) {
1245
rc |= update_local_ref(ref, transaction, display_state,
1244
- rm, summary_width);
1246
+ rm, summary_width, config);
1247
free(ref);
1248
} else if (write_fetch_head || dry_run) {
1249
/*
@@ -1265,7 +1267,7 @@ static int store_updated_refs(struct display_state *display_state,
1267
"branches"), remote_name);
1268
1269
if (advice_enabled(ADVICE_FETCH_SHOW_FORCED_UPDATES)) {
1268
- if (!fetch_show_forced_updates) {
1270
+ if (!config->show_forced_updates) {
1271
warning(_(warn_show_forced_updates));
1272
} else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
1273
warning(_(warn_time_show_forced_updates),
@@ -1326,7 +1328,8 @@ static int fetch_and_consume_refs(struct display_state *display_state,
1328
struct transport *transport,
1329
struct ref_transaction *transaction,
1330
struct ref *ref_map,
1329
- struct fetch_head *fetch_head)
1331
+ struct fetch_head *fetch_head,
1332
+ const struct fetch_config *config)
1333
{
1334
int connectivity_checked = 1;
1335
int ret;
@@ -1349,7 +1352,7 @@ static int fetch_and_consume_refs(struct display_state *display_state,
1352
trace2_region_enter("fetch", "consume_refs", the_repository);
1353
ret = store_updated_refs(display_state, transport->remote->name,
1354
connectivity_checked, transaction, ref_map,
1352
- fetch_head);
1355
+ fetch_head, config);
1356
trace2_region_leave("fetch", "consume_refs", the_repository);
1357
1358
out:
@@ -1520,7 +1523,8 @@ static int backfill_tags(struct display_state *display_state,
1523
struct transport *transport,
1524
struct ref_transaction *transaction,
1525
struct ref *ref_map,
1523
- struct fetch_head *fetch_head)
1526
+ struct fetch_head *fetch_head,
1527
+ const struct fetch_config *config)
1528
{
1529
int retcode, cannot_reuse;
1530
@@ -1541,7 +1545,8 @@ static int backfill_tags(struct display_state *display_state,
1545
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
1546
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
1547
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);
1550
1551
if (gsecondary) {
1552
transport_disconnect(gsecondary);
@@ -1668,7 +1673,8 @@ static int do_fetch(struct transport *transport,
1673
retcode = 1;
1674
}
1675
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)) {
1678
retcode = 1;
1679
goto cleanup;
1680
}
@@ -1691,7 +1697,7 @@ static int do_fetch(struct transport *transport,
1697
* the transaction and don't commit anything.
1698
*/
1699
if (backfill_tags(&display_state, transport, transaction, tags_ref_map,
1694
- &fetch_head))
1700
+ &fetch_head, config))
1701
retcode = 1;
1702
}
1703
@@ -2110,6 +2116,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2116
.display_format = DISPLAY_FORMAT_FULL,
2117
.prune = -1,
2118
.prune_tags = -1,
2119
+ .show_forced_updates = 1,
2120
};
2121
const char *submodule_prefix = "";
2122
const char *bundle_uri;
@@ -2207,7 +2214,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2214
N_("run 'maintenance --auto' after fetching")),
2215
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
2216
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,
2218
N_("check for forced-updates on all updated branches")),
2219
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
2220
N_("write the commit-graph after fetching")),