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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 9 additions & 3 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 7 additions & 4 deletions
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

0 commit comments

Comments
 (0)