Skip to content

Commit a4e7e31

Browse files
chooglengitster
authored andcommitted
config: add ctx arg to config_fn_t
Add a new "const struct config_context *ctx" arg to config_fn_t to hold additional information about the config iteration operation. config_context has a "struct key_value_info kvi" member that holds metadata about the config source being read (e.g. what kind of config source it is, the filename, etc). In this series, we're only interested in .kvi, so we could have just used "struct key_value_info" as an arg, but config_context makes it possible to add/adjust members in the future without changing the config_fn_t signature. We could also consider other ways of organizing the args (e.g. moving the config name and value into config_context or key_value_info), but in my experiments, the incremental benefit doesn't justify the added complexity (e.g. a config_fn_t will sometimes invoke another config_fn_t but with a different config value). In subsequent commits, the .kvi member will replace the global "struct config_reader" in config.c, making config iteration a global-free operation. It requires much more work for the machinery to provide meaningful values of .kvi, so for now, merely change the signature and call sites, pass NULL as a placeholder value, and don't rely on the arg in any meaningful way. Most of the changes are performed by contrib/coccinelle/config_fn_ctx.pending.cocci, which, for every config_fn_t: - Modifies the signature to accept "const struct config_context *ctx" - Passes "ctx" to any inner config_fn_t, if needed - Adds UNUSED attributes to "ctx", if needed Most config_fn_t instances are easily identified by seeing if they are called by the various config functions. Most of the remaining ones are manually named in the .cocci patch. Manual cleanups are still needed, but the majority of it is trivial; it's either adjusting config_fn_t that the .cocci patch didn't catch, or adding forward declarations of "struct config_context ctx" to make the signatures make sense. The non-trivial changes are in cases where we are invoking a config_fn_t outside of config machinery, and we now need to decide what value of "ctx" to pass. These cases are: - trace2/tr2_cfg.c:tr2_cfg_set_fl() This is indirectly called by git_config_set() so that the trace2 machinery can notice the new config values and update its settings using the tr2 config parsing function, i.e. tr2_cfg_cb(). - builtin/checkout.c:checkout_main() This calls git_xmerge_config() as a shorthand for parsing a CLI arg. This might be worth refactoring away in the future, since git_xmerge_config() can call git_default_config(), which can do much more than just parsing. Handle them by creating a KVI_INIT macro that initializes "struct key_value_info" to a reasonable default, and use that to construct the "ctx" arg. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0f9a51 commit a4e7e31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+515
-181
lines changed

alias.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ struct config_alias_data {
1212
struct string_list *list;
1313
};
1414

15-
static int config_alias_cb(const char *key, const char *value, void *d)
15+
static int config_alias_cb(const char *key, const char *value,
16+
const struct config_context *ctx UNUSED, void *d)
1617
{
1718
struct config_alias_data *data = d;
1819
const char *p;

archive-tar.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ static int tar_filter_config(const char *var, const char *value,
411411
return 0;
412412
}
413413

414-
static int git_tar_config(const char *var, const char *value, void *cb)
414+
static int git_tar_config(const char *var, const char *value,
415+
const struct config_context *ctx UNUSED, void *cb)
415416
{
416417
if (!strcmp(var, "tar.umask")) {
417418
if (value && !strcmp(value, "user")) {

archive-zip.c

+1
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
617617
}
618618

619619
static int archive_zip_config(const char *var, const char *value,
620+
const struct config_context *ctx UNUSED,
620621
void *data UNUSED)
621622
{
622623
return userdiff_config(var, value);

builtin/add.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ static struct option builtin_add_options[] = {
357357
OPT_END(),
358358
};
359359

360-
static int add_config(const char *var, const char *value, void *cb)
360+
static int add_config(const char *var, const char *value,
361+
const struct config_context *ctx, void *cb)
361362
{
362363
if (!strcmp(var, "add.ignoreerrors") ||
363364
!strcmp(var, "add.ignore-errors")) {
@@ -368,7 +369,7 @@ static int add_config(const char *var, const char *value, void *cb)
368369
if (git_color_config(var, value, cb) < 0)
369370
return -1;
370371

371-
return git_default_config(var, value, cb);
372+
return git_default_config(var, value, ctx, cb);
372373
}
373374

374375
static const char embedded_advice[] = N_(

builtin/blame.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ static const char *add_prefix(const char *prefix, const char *path)
694694
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
695695
}
696696

697-
static int git_blame_config(const char *var, const char *value, void *cb)
697+
static int git_blame_config(const char *var, const char *value,
698+
const struct config_context *ctx, void *cb)
698699
{
699700
if (!strcmp(var, "blame.showroot")) {
700701
show_root = git_config_bool(var, value);
@@ -767,7 +768,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
767768
if (userdiff_config(var, value) < 0)
768769
return -1;
769770

770-
return git_default_config(var, value, cb);
771+
return git_default_config(var, value, ctx, cb);
771772
}
772773

773774
static int blame_copy_callback(const struct option *option, const char *arg, int unset)

builtin/branch.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ static unsigned int colopts;
8383

8484
define_list_config_array(color_branch_slots);
8585

86-
static int git_branch_config(const char *var, const char *value, void *cb)
86+
static int git_branch_config(const char *var, const char *value,
87+
const struct config_context *ctx, void *cb)
8788
{
8889
const char *slot_name;
8990

@@ -120,7 +121,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
120121
if (git_color_config(var, value, cb) < 0)
121122
return -1;
122123

123-
return git_default_config(var, value, cb);
124+
return git_default_config(var, value, ctx, cb);
124125
}
125126

126127
static const char *branch_get_color(enum color_branch ix)

builtin/cat-file.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,13 @@ static int batch_objects(struct batch_options *opt)
873873
return retval;
874874
}
875875

876-
static int git_cat_file_config(const char *var, const char *value, void *cb)
876+
static int git_cat_file_config(const char *var, const char *value,
877+
const struct config_context *ctx, void *cb)
877878
{
878879
if (userdiff_config(var, value) < 0)
879880
return -1;
880881

881-
return git_default_config(var, value, cb);
882+
return git_default_config(var, value, ctx, cb);
882883
}
883884

884885
static int batch_option_callback(const struct option *opt,

builtin/checkout.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,8 @@ static int switch_branches(const struct checkout_opts *opts,
11861186
return ret || writeout_error;
11871187
}
11881188

1189-
static int git_checkout_config(const char *var, const char *value, void *cb)
1189+
static int git_checkout_config(const char *var, const char *value,
1190+
const struct config_context *ctx, void *cb)
11901191
{
11911192
struct checkout_opts *opts = cb;
11921193

@@ -1202,7 +1203,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
12021203
if (starts_with(var, "submodule."))
12031204
return git_default_submodule_config(var, value, NULL);
12041205

1205-
return git_xmerge_config(var, value, NULL);
1206+
return git_xmerge_config(var, value, ctx, NULL);
12061207
}
12071208

12081209
static void setup_new_branch_info_and_source_tree(
@@ -1689,8 +1690,13 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
16891690
}
16901691

16911692
if (opts->conflict_style) {
1693+
struct key_value_info kvi = KVI_INIT;
1694+
struct config_context ctx = {
1695+
.kvi = &kvi,
1696+
};
16921697
opts->merge = 1; /* implied */
1693-
git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
1698+
git_xmerge_config("merge.conflictstyle", opts->conflict_style,
1699+
&ctx, NULL);
16941700
}
16951701
if (opts->force) {
16961702
opts->discard_changes = 1;

builtin/clean.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struct menu_stuff {
103103

104104
define_list_config_array(color_interactive_slots);
105105

106-
static int git_clean_config(const char *var, const char *value, void *cb)
106+
static int git_clean_config(const char *var, const char *value,
107+
const struct config_context *ctx, void *cb)
107108
{
108109
const char *slot_name;
109110

@@ -133,7 +134,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
133134
if (git_color_config(var, value, cb) < 0)
134135
return -1;
135136

136-
return git_default_config(var, value, cb);
137+
return git_default_config(var, value, ctx, cb);
137138
}
138139

139140
static const char *clean_get_color(enum color_clean ix)

builtin/clone.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ static int checkout(int submodule_progress, int filter_submodules)
790790
return err;
791791
}
792792

793-
static int git_clone_config(const char *k, const char *v, void *cb)
793+
static int git_clone_config(const char *k, const char *v,
794+
const struct config_context *ctx, void *cb)
794795
{
795796
if (!strcmp(k, "clone.defaultremotename")) {
796797
free(remote_name);
@@ -801,17 +802,19 @@ static int git_clone_config(const char *k, const char *v, void *cb)
801802
if (!strcmp(k, "clone.filtersubmodules"))
802803
config_filter_submodules = git_config_bool(k, v);
803804

804-
return git_default_config(k, v, cb);
805+
return git_default_config(k, v, ctx, cb);
805806
}
806807

807-
static int write_one_config(const char *key, const char *value, void *data)
808+
static int write_one_config(const char *key, const char *value,
809+
const struct config_context *ctx,
810+
void *data)
808811
{
809812
/*
810813
* give git_clone_config a chance to write config values back to the
811814
* environment, since git_config_set_multivar_gently only deals with
812815
* config-file writes
813816
*/
814-
int apply_failed = git_clone_config(key, value, data);
817+
int apply_failed = git_clone_config(key, value, ctx, data);
815818
if (apply_failed)
816819
return apply_failed;
817820

builtin/column.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static const char * const builtin_column_usage[] = {
1313
};
1414
static unsigned int colopts;
1515

16-
static int column_config(const char *var, const char *value, void *cb)
16+
static int column_config(const char *var, const char *value,
17+
const struct config_context *ctx UNUSED, void *cb)
1718
{
1819
return git_column_config(var, value, cb, &colopts);
1920
}

builtin/commit-graph.c

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ static int write_option_max_new_filters(const struct option *opt,
186186
}
187187

188188
static int git_commit_graph_write_config(const char *var, const char *value,
189+
const struct config_context *ctx UNUSED,
189190
void *cb UNUSED)
190191
{
191192
if (!strcmp(var, "commitgraph.maxnewfilters"))

builtin/commit.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,8 @@ static int parse_status_slot(const char *slot)
14051405
return LOOKUP_CONFIG(color_status_slots, slot);
14061406
}
14071407

1408-
static int git_status_config(const char *k, const char *v, void *cb)
1408+
static int git_status_config(const char *k, const char *v,
1409+
const struct config_context *ctx, void *cb)
14091410
{
14101411
struct wt_status *s = cb;
14111412
const char *slot_name;
@@ -1490,7 +1491,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
14901491
s->detect_rename = git_config_rename(k, v);
14911492
return 0;
14921493
}
1493-
return git_diff_ui_config(k, v, NULL);
1494+
return git_diff_ui_config(k, v, ctx, NULL);
14941495
}
14951496

14961497
int cmd_status(int argc, const char **argv, const char *prefix)
@@ -1605,7 +1606,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
16051606
return 0;
16061607
}
16071608

1608-
static int git_commit_config(const char *k, const char *v, void *cb)
1609+
static int git_commit_config(const char *k, const char *v,
1610+
const struct config_context *ctx, void *cb)
16091611
{
16101612
struct wt_status *s = cb;
16111613

@@ -1627,7 +1629,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
16271629
return 0;
16281630
}
16291631

1630-
return git_status_config(k, v, s);
1632+
return git_status_config(k, v, ctx, s);
16311633
}
16321634

16331635
int cmd_commit(int argc, const char **argv, const char *prefix)

builtin/config.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static void show_config_scope(struct strbuf *buf)
217217
}
218218

219219
static int show_all_config(const char *key_, const char *value_,
220+
const struct config_context *ctx UNUSED,
220221
void *cb UNUSED)
221222
{
222223
if (show_origin || show_scope) {
@@ -301,7 +302,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
301302
return 0;
302303
}
303304

304-
static int collect_config(const char *key_, const char *value_, void *cb)
305+
static int collect_config(const char *key_, const char *value_,
306+
const struct config_context *ctx UNUSED, void *cb)
305307
{
306308
struct strbuf_list *values = cb;
307309

@@ -470,6 +472,7 @@ static const char *get_colorbool_slot;
470472
static char parsed_color[COLOR_MAXLEN];
471473

472474
static int git_get_color_config(const char *var, const char *value,
475+
const struct config_context *ctx UNUSED,
473476
void *cb UNUSED)
474477
{
475478
if (!strcmp(var, get_color_slot)) {
@@ -503,6 +506,7 @@ static int get_colorbool_found;
503506
static int get_diff_color_found;
504507
static int get_color_ui_found;
505508
static int git_get_colorbool_config(const char *var, const char *value,
509+
const struct config_context *ctx UNUSED,
506510
void *data UNUSED)
507511
{
508512
if (!strcmp(var, get_colorbool_slot))
@@ -561,7 +565,9 @@ struct urlmatch_current_candidate_value {
561565
struct strbuf value;
562566
};
563567

564-
static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
568+
static int urlmatch_collect_fn(const char *var, const char *value,
569+
const struct config_context *ctx UNUSED,
570+
void *cb)
565571
{
566572
struct string_list *values = cb;
567573
struct string_list_item *item = string_list_insert(values, var);

builtin/difftool.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ static const char *const builtin_difftool_usage[] = {
4040
NULL
4141
};
4242

43-
static int difftool_config(const char *var, const char *value, void *cb)
43+
static int difftool_config(const char *var, const char *value,
44+
const struct config_context *ctx, void *cb)
4445
{
4546
if (!strcmp(var, "difftool.trustexitcode")) {
4647
trust_exit_code = git_config_bool(var, value);
4748
return 0;
4849
}
4950

50-
return git_default_config(var, value, cb);
51+
return git_default_config(var, value, ctx, cb);
5152
}
5253

5354
static int print_tool_help(void)

builtin/fetch.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ struct fetch_config {
110110
int submodule_fetch_jobs;
111111
};
112112

113-
static int git_fetch_config(const char *k, const char *v, void *cb)
113+
static int git_fetch_config(const char *k, const char *v,
114+
const struct config_context *ctx, void *cb)
114115
{
115116
struct fetch_config *fetch_config = cb;
116117

@@ -164,7 +165,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
164165
"fetch.output", v);
165166
}
166167

167-
return git_default_config(k, v, cb);
168+
return git_default_config(k, v, ctx, cb);
168169
}
169170

170171
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@@ -1799,7 +1800,9 @@ struct remote_group_data {
17991800
struct string_list *list;
18001801
};
18011802

1802-
static int get_remote_group(const char *key, const char *value, void *priv)
1803+
static int get_remote_group(const char *key, const char *value,
1804+
const struct config_context *ctx UNUSED,
1805+
void *priv)
18031806
{
18041807
struct remote_group_data *g = priv;
18051808

builtin/fsmonitor--daemon.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static int fsmonitor__start_timeout_sec = 60;
3737
#define FSMONITOR__ANNOUNCE_STARTUP "fsmonitor.announcestartup"
3838
static int fsmonitor__announce_startup = 0;
3939

40-
static int fsmonitor_config(const char *var, const char *value, void *cb)
40+
static int fsmonitor_config(const char *var, const char *value,
41+
const struct config_context *ctx, void *cb)
4142
{
4243
if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
4344
int i = git_config_int(var, value);
@@ -67,7 +68,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
6768
return 0;
6869
}
6970

70-
return git_default_config(var, value, cb);
71+
return git_default_config(var, value, ctx, cb);
7172
}
7273

7374
/*

builtin/grep.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,14 @@ static int wait_all(void)
290290
return hit;
291291
}
292292

293-
static int grep_cmd_config(const char *var, const char *value, void *cb)
293+
static int grep_cmd_config(const char *var, const char *value,
294+
const struct config_context *ctx, void *cb)
294295
{
295-
int st = grep_config(var, value, cb);
296+
int st = grep_config(var, value, ctx, cb);
296297

297298
if (git_color_config(var, value, cb) < 0)
298299
st = -1;
299-
else if (git_default_config(var, value, cb) < 0)
300+
else if (git_default_config(var, value, ctx, cb) < 0)
300301
st = -1;
301302

302303
if (!strcmp(var, "grep.threads")) {

builtin/help.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ static int add_man_viewer_info(const char *var, const char *value)
398398
return 0;
399399
}
400400

401-
static int git_help_config(const char *var, const char *value, void *cb)
401+
static int git_help_config(const char *var, const char *value,
402+
const struct config_context *ctx, void *cb)
402403
{
403404
if (!strcmp(var, "help.format")) {
404405
if (!value)
@@ -421,7 +422,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
421422
if (starts_with(var, "man."))
422423
return add_man_viewer_info(var, value);
423424

424-
return git_default_config(var, value, cb);
425+
return git_default_config(var, value, ctx, cb);
425426
}
426427

427428
static struct cmdnames main_cmds, other_cmds;

0 commit comments

Comments
 (0)