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 <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Glen Choo committed Jun 28, 2023 at 19:26 UTC a4e7e317f8f27f861321e6eb08b9c8c0f3ab570c
91 files changed +515 -181
alias.c
+2 -1
@@ -12,7 +12,8 @@ struct config_alias_data {
12 struct string_list *list;
13 };
14
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)
17 {
18 struct config_alias_data *data = d;
19 const char *p;
archive-tar.c
+2 -1
@@ -411,7 +411,8 @@ static int tar_filter_config(const char *var, const char *value,
411 return 0;
412 }
413
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)
416 {
417 if (!strcmp(var, "tar.umask")) {
418 if (value && !strcmp(value, "user")) {
archive-zip.c
+1
@@ -617,6 +617,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
617 }
618
619 static int archive_zip_config(const char *var, const char *value,
620 + const struct config_context *ctx UNUSED,
621 void *data UNUSED)
622 {
623 return userdiff_config(var, value);
builtin/add.c
+3 -2
@@ -357,7 +357,8 @@ static struct option builtin_add_options[] = {
357 OPT_END(),
358 };
359
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)
362 {
363 if (!strcmp(var, "add.ignoreerrors") ||
364 !strcmp(var, "add.ignore-errors")) {
@@ -368,7 +369,7 @@ static int add_config(const char *var, const char *value, void *cb)
369 if (git_color_config(var, value, cb) < 0)
370 return -1;
371
371 - return git_default_config(var, value, cb);
372 + return git_default_config(var, value, ctx, cb);
373 }
374
375 static const char embedded_advice[] = N_(
builtin/blame.c
+3 -2
@@ -694,7 +694,8 @@ static const char *add_prefix(const char *prefix, const char *path)
694 return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
695 }
696
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)
699 {
700 if (!strcmp(var, "blame.showroot")) {
701 show_root = git_config_bool(var, value);
@@ -767,7 +768,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
768 if (userdiff_config(var, value) < 0)
769 return -1;
770
770 - return git_default_config(var, value, cb);
771 + return git_default_config(var, value, ctx, cb);
772 }
773
774 static int blame_copy_callback(const struct option *option, const char *arg, int unset)
builtin/branch.c
+3 -2
@@ -83,7 +83,8 @@ static unsigned int colopts;
83
84 define_list_config_array(color_branch_slots);
85
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)
88 {
89 const char *slot_name;
90
@@ -120,7 +121,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
121 if (git_color_config(var, value, cb) < 0)
122 return -1;
123
123 - return git_default_config(var, value, cb);
124 + return git_default_config(var, value, ctx, cb);
125 }
126
127 static const char *branch_get_color(enum color_branch ix)
builtin/cat-file.c
+3 -2
@@ -873,12 +873,13 @@ static int batch_objects(struct batch_options *opt)
873 return retval;
874 }
875
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)
878 {
879 if (userdiff_config(var, value) < 0)
880 return -1;
881
881 - return git_default_config(var, value, cb);
882 + return git_default_config(var, value, ctx, cb);
883 }
884
885 static int batch_option_callback(const struct option *opt,
builtin/checkout.c
+9 -3
@@ -1186,7 +1186,8 @@ static int switch_branches(const struct checkout_opts *opts,
1186 return ret || writeout_error;
1187 }
1188
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)
1191 {
1192 struct checkout_opts *opts = cb;
1193
@@ -1202,7 +1203,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
1203 if (starts_with(var, "submodule."))
1204 return git_default_submodule_config(var, value, NULL);
1205
1205 - return git_xmerge_config(var, value, NULL);
1206 + return git_xmerge_config(var, value, ctx, NULL);
1207 }
1208
1209 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,
1690 }
1691
1692 if (opts->conflict_style) {
1693 + struct key_value_info kvi = KVI_INIT;
1694 + struct config_context ctx = {
1695 + .kvi = &kvi,
1696 + };
1697 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);
1700 }
1701 if (opts->force) {
1702 opts->discard_changes = 1;
builtin/clean.c
+3 -2
@@ -103,7 +103,8 @@ struct menu_stuff {
103
104 define_list_config_array(color_interactive_slots);
105
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)
108 {
109 const char *slot_name;
110
@@ -133,7 +134,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
134 if (git_color_config(var, value, cb) < 0)
135 return -1;
136
136 - return git_default_config(var, value, cb);
137 + return git_default_config(var, value, ctx, cb);
138 }
139
140 static const char *clean_get_color(enum color_clean ix)
builtin/clone.c
+7 -4
@@ -790,7 +790,8 @@ static int checkout(int submodule_progress, int filter_submodules)
790 return err;
791 }
792
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)
795 {
796 if (!strcmp(k, "clone.defaultremotename")) {
797 free(remote_name);
@@ -801,17 +802,19 @@ static int git_clone_config(const char *k, const char *v, void *cb)
802 if (!strcmp(k, "clone.filtersubmodules"))
803 config_filter_submodules = git_config_bool(k, v);
804
804 - return git_default_config(k, v, cb);
805 + return git_default_config(k, v, ctx, cb);
806 }
807
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)
811 {
812 /*
813 * give git_clone_config a chance to write config values back to the
814 * environment, since git_config_set_multivar_gently only deals with
815 * config-file writes
816 */
814 - int apply_failed = git_clone_config(key, value, data);
817 + int apply_failed = git_clone_config(key, value, ctx, data);
818 if (apply_failed)
819 return apply_failed;
820
builtin/column.c
+2 -1
@@ -13,7 +13,8 @@ static const char * const builtin_column_usage[] = {
13 };
14 static unsigned int colopts;
15
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)
18 {
19 return git_column_config(var, value, cb, &colopts);
20 }
builtin/commit-graph.c
+1
@@ -186,6 +186,7 @@ static int write_option_max_new_filters(const struct option *opt,
186 }
187
188 static int git_commit_graph_write_config(const char *var, const char *value,
189 + const struct config_context *ctx UNUSED,
190 void *cb UNUSED)
191 {
192 if (!strcmp(var, "commitgraph.maxnewfilters"))
builtin/commit.c
+6 -4
@@ -1405,7 +1405,8 @@ static int parse_status_slot(const char *slot)
1405 return LOOKUP_CONFIG(color_status_slots, slot);
1406 }
1407
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)
1410 {
1411 struct wt_status *s = cb;
1412 const char *slot_name;
@@ -1490,7 +1491,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1491 s->detect_rename = git_config_rename(k, v);
1492 return 0;
1493 }
1493 - return git_diff_ui_config(k, v, NULL);
1494 + return git_diff_ui_config(k, v, ctx, NULL);
1495 }
1496
1497 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)
1606 return 0;
1607 }
1608
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)
1611 {
1612 struct wt_status *s = cb;
1613
@@ -1627,7 +1629,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
1629 return 0;
1630 }
1631
1630 - return git_status_config(k, v, s);
1632 + return git_status_config(k, v, ctx, s);
1633 }
1634
1635 int cmd_commit(int argc, const char **argv, const char *prefix)
builtin/config.c
+8 -2
@@ -217,6 +217,7 @@ static void show_config_scope(struct strbuf *buf)
217 }
218
219 static int show_all_config(const char *key_, const char *value_,
220 + const struct config_context *ctx UNUSED,
221 void *cb UNUSED)
222 {
223 if (show_origin || show_scope) {
@@ -301,7 +302,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
302 return 0;
303 }
304
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)
307 {
308 struct strbuf_list *values = cb;
309
@@ -470,6 +472,7 @@ static const char *get_colorbool_slot;
472 static char parsed_color[COLOR_MAXLEN];
473
474 static int git_get_color_config(const char *var, const char *value,
475 + const struct config_context *ctx UNUSED,
476 void *cb UNUSED)
477 {
478 if (!strcmp(var, get_color_slot)) {
@@ -503,6 +506,7 @@ static int get_colorbool_found;
506 static int get_diff_color_found;
507 static int get_color_ui_found;
508 static int git_get_colorbool_config(const char *var, const char *value,
509 + const struct config_context *ctx UNUSED,
510 void *data UNUSED)
511 {
512 if (!strcmp(var, get_colorbool_slot))
@@ -561,7 +565,9 @@ struct urlmatch_current_candidate_value {
565 struct strbuf value;
566 };
567
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)
571 {
572 struct string_list *values = cb;
573 struct string_list_item *item = string_list_insert(values, var);
builtin/difftool.c
+3 -2
@@ -40,14 +40,15 @@ static const char *const builtin_difftool_usage[] = {
40 NULL
41 };
42
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)
45 {
46 if (!strcmp(var, "difftool.trustexitcode")) {
47 trust_exit_code = git_config_bool(var, value);
48 return 0;
49 }
50
50 - return git_default_config(var, value, cb);
51 + return git_default_config(var, value, ctx, cb);
52 }
53
54 static int print_tool_help(void)
builtin/fetch.c
+6 -3
@@ -110,7 +110,8 @@ struct fetch_config {
110 int submodule_fetch_jobs;
111 };
112
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)
115 {
116 struct fetch_config *fetch_config = cb;
117
@@ -164,7 +165,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
165 "fetch.output", v);
166 }
167
167 - return git_default_config(k, v, cb);
168 + return git_default_config(k, v, ctx, cb);
169 }
170
171 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@@ -1799,7 +1800,9 @@ struct remote_group_data {
1800 struct string_list *list;
1801 };
1802
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)
1806 {
1807 struct remote_group_data *g = priv;
1808
builtin/fsmonitor--daemon.c
+3 -2
@@ -37,7 +37,8 @@ static int fsmonitor__start_timeout_sec = 60;
37 #define FSMONITOR__ANNOUNCE_STARTUP "fsmonitor.announcestartup"
38 static int fsmonitor__announce_startup = 0;
39
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)
42 {
43 if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
44 int i = git_config_int(var, value);
@@ -67,7 +68,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
68 return 0;
69 }
70
70 - return git_default_config(var, value, cb);
71 + return git_default_config(var, value, ctx, cb);
72 }
73
74 /*
builtin/grep.c
+4 -3
@@ -290,13 +290,14 @@ static int wait_all(void)
290 return hit;
291 }
292
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)
295 {
295 - int st = grep_config(var, value, cb);
296 + int st = grep_config(var, value, ctx, cb);
297
298 if (git_color_config(var, value, cb) < 0)
299 st = -1;
299 - else if (git_default_config(var, value, cb) < 0)
300 + else if (git_default_config(var, value, ctx, cb) < 0)
301 st = -1;
302
303 if (!strcmp(var, "grep.threads")) {
builtin/help.c
+3 -2
@@ -398,7 +398,8 @@ static int add_man_viewer_info(const char *var, const char *value)
398 return 0;
399 }
400
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)
403 {
404 if (!strcmp(var, "help.format")) {
405 if (!value)
@@ -421,7 +422,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
422 if (starts_with(var, "man."))
423 return add_man_viewer_info(var, value);
424
424 - return git_default_config(var, value, cb);
425 + return git_default_config(var, value, ctx, cb);
426 }
427
428 static struct cmdnames main_cmds, other_cmds;
builtin/index-pack.c
+3 -2
@@ -1581,7 +1581,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1581 strbuf_release(&pack_name);
1582 }
1583
1584 -static int git_index_pack_config(const char *k, const char *v, void *cb)
1584 +static int git_index_pack_config(const char *k, const char *v,
1585 + const struct config_context *ctx, void *cb)
1586 {
1587 struct pack_idx_option *opts = cb;
1588
@@ -1608,7 +1609,7 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
1609 else
1610 opts->flags &= ~WRITE_REV;
1611 }
1611 - return git_default_config(k, v, cb);
1612 + return git_default_config(k, v, ctx, cb);
1613 }
1614
1615 static int cmp_uint32(const void *a_, const void *b_)
builtin/log.c
+6 -4
@@ -564,7 +564,8 @@ static int cmd_log_walk(struct rev_info *rev)
564 return retval;
565 }
566
567 -static int git_log_config(const char *var, const char *value, void *cb)
567 +static int git_log_config(const char *var, const char *value,
568 + const struct config_context *ctx, void *cb)
569 {
570 const char *slot_name;
571
@@ -613,7 +614,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
614 return 0;
615 }
616
616 - return git_diff_ui_config(var, value, cb);
617 + return git_diff_ui_config(var, value, ctx, cb);
618 }
619
620 int cmd_whatchanged(int argc, const char **argv, const char *prefix)
@@ -979,7 +980,8 @@ static enum cover_from_description parse_cover_from_description(const char *arg)
980 die(_("%s: invalid cover from description mode"), arg);
981 }
982
982 -static int git_format_config(const char *var, const char *value, void *cb)
983 +static int git_format_config(const char *var, const char *value,
984 + const struct config_context *ctx, void *cb)
985 {
986 if (!strcmp(var, "format.headers")) {
987 if (!value)
@@ -1108,7 +1110,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
1110 if (!strcmp(var, "diff.noprefix"))
1111 return 0;
1112
1111 - return git_log_config(var, value, cb);
1113 + return git_log_config(var, value, ctx, cb);
1114 }
1115
1116 static const char *output_directory = NULL;
builtin/merge.c
+4 -3
@@ -623,7 +623,8 @@ static void parse_branch_merge_options(char *bmo)
623 free(argv);
624 }
625
626 -static int git_merge_config(const char *k, const char *v, void *cb)
626 +static int git_merge_config(const char *k, const char *v,
627 + const struct config_context *ctx, void *cb)
628 {
629 int status;
630 const char *str;
@@ -668,10 +669,10 @@ static int git_merge_config(const char *k, const char *v, void *cb)
669 return 0;
670 }
671
671 - status = fmt_merge_msg_config(k, v, cb);
672 + status = fmt_merge_msg_config(k, v, ctx, cb);
673 if (status)
674 return status;
674 - return git_diff_ui_config(k, v, cb);
675 + return git_diff_ui_config(k, v, ctx, cb);
676 }
677
678 static int read_tree_trivial(struct object_id *common, struct object_id *head,
builtin/multi-pack-index.c
+1
@@ -82,6 +82,7 @@ static struct option *add_common_options(struct option *prev)
82 }
83
84 static int git_multi_pack_index_write_config(const char *var, const char *value,
85 + const struct config_context *ctx UNUSED,
86 void *cb UNUSED)
87 {
88 if (!strcmp(var, "pack.writebitmaphashcache")) {
builtin/pack-objects.c
+3 -2
@@ -3135,7 +3135,8 @@ static void prepare_pack(int window, int depth)
3135 free(delta_list);
3136 }
3137
3138 -static int git_pack_config(const char *k, const char *v, void *cb)
3138 +static int git_pack_config(const char *k, const char *v,
3139 + const struct config_context *ctx, void *cb)
3140 {
3141 if (!strcmp(k, "pack.window")) {
3142 window = git_config_int(k, v);
@@ -3227,7 +3228,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
3228 ex->uri = xstrdup(pack_end + 1);
3229 oidmap_put(&configured_exclusions, ex);
3230 }
3230 - return git_default_config(k, v, cb);
3231 + return git_default_config(k, v, ctx, cb);
3232 }
3233
3234 /* Counters for trace2 output when in --stdin-packs mode. */
builtin/patch-id.c
+3 -2
@@ -196,7 +196,8 @@ struct patch_id_opts {
196 int verbatim;
197 };
198
199 -static int git_patch_id_config(const char *var, const char *value, void *cb)
199 +static int git_patch_id_config(const char *var, const char *value,
200 + const struct config_context *ctx, void *cb)
201 {
202 struct patch_id_opts *opts = cb;
203
@@ -209,7 +210,7 @@ static int git_patch_id_config(const char *var, const char *value, void *cb)
210 return 0;
211 }
212
212 - return git_default_config(var, value, cb);
213 + return git_default_config(var, value, ctx, cb);
214 }
215
216 int cmd_patch_id(int argc, const char **argv, const char *prefix)
builtin/pull.c
+3 -2
@@ -361,7 +361,8 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified)
361 /**
362 * Read config variables.
363 */
364 -static int git_pull_config(const char *var, const char *value, void *cb)
364 +static int git_pull_config(const char *var, const char *value,
365 + const struct config_context *ctx, void *cb)
366 {
367 if (!strcmp(var, "rebase.autostash")) {
368 config_autostash = git_config_bool(var, value);
@@ -374,7 +375,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
375 check_trust_level = 0;
376 }
377
377 - return git_default_config(var, value, cb);
378 + return git_default_config(var, value, ctx, cb);
379 }
380
381 /**
builtin/push.c
+3 -2
@@ -510,7 +510,8 @@ static void set_push_cert_flags(int *flags, int v)
510 }
511
512
513 -static int git_push_config(const char *k, const char *v, void *cb)
513 +static int git_push_config(const char *k, const char *v,
514 + const struct config_context *ctx, void *cb)
515 {
516 const char *slot_name;
517 int *flags = cb;
@@ -577,7 +578,7 @@ static int git_push_config(const char *k, const char *v, void *cb)
578 return 0;
579 }
580
580 - return git_default_config(k, v, NULL);
581 + return git_default_config(k, v, ctx, NULL);
582 }
583
584 int cmd_push(int argc, const char **argv, const char *prefix)
builtin/read-tree.c
+3 -2
@@ -102,12 +102,13 @@ static int debug_merge(const struct cache_entry * const *stages,
102 return 0;
103 }
104
105 -static int git_read_tree_config(const char *var, const char *value, void *cb)
105 +static int git_read_tree_config(const char *var, const char *value,
106 + const struct config_context *ctx, void *cb)
107 {
108 if (!strcmp(var, "submodule.recurse"))
109 return git_default_submodule_config(var, value, cb);
110
110 - return git_default_config(var, value, cb);
111 + return git_default_config(var, value, ctx, cb);
112 }
113
114 int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
builtin/rebase.c
+3 -2
@@ -772,7 +772,8 @@ static void parse_rebase_merges_value(struct rebase_options *options, const char
772 die(_("Unknown rebase-merges mode: %s"), value);
773 }
774
775 -static int rebase_config(const char *var, const char *value, void *data)
775 +static int rebase_config(const char *var, const char *value,
776 + const struct config_context *ctx, void *data)
777 {
778 struct rebase_options *opts = data;
779
@@ -831,7 +832,7 @@ static int rebase_config(const char *var, const char *value, void *data)
832 return git_config_string(&opts->default_backend, var, value);
833 }
834
834 - return git_default_config(var, value, data);
835 + return git_default_config(var, value, ctx, data);
836 }
837
838 static int checkout_up_to_date(struct rebase_options *options)
builtin/receive-pack.c
+3 -2
@@ -139,7 +139,8 @@ static enum deny_action parse_deny_action(const char *var, const char *value)
139 return DENY_IGNORE;
140 }
141
142 -static int receive_pack_config(const char *var, const char *value, void *cb)
142 +static int receive_pack_config(const char *var, const char *value,
143 + const struct config_context *ctx, void *cb)
144 {
145 int status = parse_hide_refs_config(var, value, "receive", &hidden_refs);
146
@@ -266,7 +267,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
267 return 0;
268 }
269
269 - return git_default_config(var, value, cb);
270 + return git_default_config(var, value, ctx, cb);
271 }
272
273 static void show_ref(const char *path, const struct object_id *oid)
builtin/reflog.c
+4 -3
@@ -108,7 +108,8 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
108 #define EXPIRE_TOTAL 01
109 #define EXPIRE_UNREACH 02
110
111 -static int reflog_expire_config(const char *var, const char *value, void *cb)
111 +static int reflog_expire_config(const char *var, const char *value,
112 + const struct config_context *ctx, void *cb)
113 {
114 const char *pattern, *key;
115 size_t pattern_len;
@@ -117,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
118 struct reflog_expire_cfg *ent;
119
120 if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
120 - return git_default_config(var, value, cb);
121 + return git_default_config(var, value, ctx, cb);
122
123 if (!strcmp(key, "reflogexpire")) {
124 slot = EXPIRE_TOTAL;
@@ -128,7 +129,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
129 if (git_config_expiry_date(&expire, var, value))
130 return -1;
131 } else
131 - return git_default_config(var, value, cb);
132 + return git_default_config(var, value, ctx, cb);
133
134 if (!pattern) {
135 switch (slot) {
builtin/remote.c
+5 -2
@@ -268,6 +268,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
268 #define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
269
270 static int config_read_branches(const char *key, const char *value,
271 + const struct config_context *ctx UNUSED,
272 void *data UNUSED)
273 {
274 const char *orig_key = key;
@@ -645,7 +646,7 @@ struct push_default_info
646 };
647
648 static int config_read_push_default(const char *key, const char *value,
648 - void *cb)
649 + const struct config_context *ctx UNUSED, void *cb)
650 {
651 struct push_default_info* info = cb;
652 if (strcmp(key, "remote.pushdefault") ||
@@ -1494,7 +1495,9 @@ static int prune(int argc, const char **argv, const char *prefix)
1495 return result;
1496 }
1497
1497 -static int get_remote_default(const char *key, const char *value UNUSED, void *priv)
1498 +static int get_remote_default(const char *key, const char *value UNUSED,
1499 + const struct config_context *ctx UNUSED,
1500 + void *priv)
1501 {
1502 if (strcmp(key, "remotes.default") == 0) {
1503 int *found = priv;
builtin/repack.c
+3 -2
@@ -59,7 +59,8 @@ struct pack_objects_args {
59 int local;
60 };
61
62 -static int repack_config(const char *var, const char *value, void *cb)
62 +static int repack_config(const char *var, const char *value,
63 + const struct config_context *ctx, void *cb)
64 {
65 struct pack_objects_args *cruft_po_args = cb;
66 if (!strcmp(var, "repack.usedeltabaseoffset")) {
@@ -91,7 +92,7 @@ static int repack_config(const char *var, const char *value, void *cb)
92 return git_config_string(&cruft_po_args->depth, var, value);
93 if (!strcmp(var, "repack.cruftthreads"))
94 return git_config_string(&cruft_po_args->threads, var, value);
94 - return git_default_config(var, value, cb);
95 + return git_default_config(var, value, ctx, cb);
96 }
97
98 /*
builtin/reset.c
+3 -2
@@ -312,12 +312,13 @@ static int reset_refs(const char *rev, const struct object_id *oid)
312 return update_ref_status;
313 }
314
315 -static int git_reset_config(const char *var, const char *value, void *cb)
315 +static int git_reset_config(const char *var, const char *value,
316 + const struct config_context *ctx, void *cb)
317 {
318 if (!strcmp(var, "submodule.recurse"))
319 return git_default_submodule_config(var, value, cb);
320
320 - return git_default_config(var, value, cb);
321 + return git_default_config(var, value, ctx, cb);
322 }
323
324 int cmd_reset(int argc, const char **argv, const char *prefix)
builtin/send-pack.c
+3 -2
@@ -131,7 +131,8 @@ static void print_helper_status(struct ref *ref)
131 strbuf_release(&buf);
132 }
133
134 -static int send_pack_config(const char *k, const char *v, void *cb)
134 +static int send_pack_config(const char *k, const char *v,
135 + const struct config_context *ctx, void *cb)
136 {
137 if (!strcmp(k, "push.gpgsign")) {
138 const char *value;
@@ -151,7 +152,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
152 }
153 }
154 }
154 - return git_default_config(k, v, cb);
155 + return git_default_config(k, v, ctx, cb);
156 }
157
158 int cmd_send_pack(int argc, const char **argv, const char *prefix)
builtin/show-branch.c
+3 -2
@@ -559,7 +559,8 @@ static void append_one_rev(const char *av)
559 die("bad sha1 reference %s", av);
560 }
561
562 -static int git_show_branch_config(const char *var, const char *value, void *cb)
562 +static int git_show_branch_config(const char *var, const char *value,
563 + const struct config_context *ctx, void *cb)
564 {
565 if (!strcmp(var, "showbranch.default")) {
566 if (!value)
@@ -582,7 +583,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
583 if (git_color_config(var, value, cb) < 0)
584 return -1;
585
585 - return git_default_config(var, value, cb);
586 + return git_default_config(var, value, ctx, cb);
587 }
588
589 static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
builtin/stash.c
+3 -2
@@ -837,7 +837,8 @@ static int show_stat = 1;
837 static int show_patch;
838 static int show_include_untracked;
839
840 -static int git_stash_config(const char *var, const char *value, void *cb)
840 +static int git_stash_config(const char *var, const char *value,
841 + const struct config_context *ctx, void *cb)
842 {
843 if (!strcmp(var, "stash.showstat")) {
844 show_stat = git_config_bool(var, value);
@@ -851,7 +852,7 @@ static int git_stash_config(const char *var, const char *value, void *cb)
852 show_include_untracked = git_config_bool(var, value);
853 return 0;
854 }
854 - return git_diff_basic_config(var, value, cb);
855 + return git_diff_basic_config(var, value, ctx, cb);
856 }
857
858 static void diff_include_untracked(const struct stash_info *info, struct diff_options *diff_opt)
builtin/submodule--helper.c
+1
@@ -2192,6 +2192,7 @@ static int update_clone_task_finished(int result,
2192 }
2193
2194 static int git_update_clone_config(const char *var, const char *value,
2195 + const struct config_context *ctx UNUSED,
2196 void *cb)
2197 {
2198 int *max_jobs = cb;
builtin/tag.c
+3 -2
@@ -188,7 +188,8 @@ static const char tag_template_nocleanup[] =
188 "Lines starting with '%c' will be kept; you may remove them"
189 " yourself if you want to.\n");
190
191 -static int git_tag_config(const char *var, const char *value, void *cb)
191 +static int git_tag_config(const char *var, const char *value,
192 + const struct config_context *ctx, void *cb)
193 {
194 if (!strcmp(var, "tag.gpgsign")) {
195 config_sign_tag = git_config_bool(var, value);
@@ -213,7 +214,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
214 if (git_color_config(var, value, cb) < 0)
215 return -1;
216
216 - return git_default_config(var, value, cb);
217 + return git_default_config(var, value, ctx, cb);
218 }
219
220 static void write_tag_body(int fd, const struct object_id *oid)
builtin/var.c
+3 -2
@@ -71,13 +71,14 @@ static const struct git_var *get_git_var(const char *var)
71 return NULL;
72 }
73
74 -static int show_config(const char *var, const char *value, void *cb)
74 +static int show_config(const char *var, const char *value,
75 + const struct config_context *ctx, void *cb)
76 {
77 if (value)
78 printf("%s=%s\n", var, value);
79 else
80 printf("%s\n", var);
80 - return git_default_config(var, value, cb);
81 + return git_default_config(var, value, ctx, cb);
82 }
83
84 int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
builtin/worktree.c
+3 -2
@@ -128,14 +128,15 @@ static int verbose;
128 static int guess_remote;
129 static timestamp_t expire;
130
131 -static int git_worktree_config(const char *var, const char *value, void *cb)
131 +static int git_worktree_config(const char *var, const char *value,
132 + const struct config_context *ctx, void *cb)
133 {
134 if (!strcmp(var, "worktree.guessremote")) {
135 guess_remote = git_config_bool(var, value);
136 return 0;
137 }
138
138 - return git_default_config(var, value, cb);
139 + return git_default_config(var, value, ctx, cb);
140 }
141
142 static int delete_git_dir(const char *id)
bundle-uri.c
+6 -2
@@ -224,7 +224,9 @@ static int bundle_list_update(const char *key, const char *value,
224 return 0;
225 }
226
227 -static int config_to_bundle_list(const char *key, const char *value, void *data)
227 +static int config_to_bundle_list(const char *key, const char *value,
228 + const struct config_context *ctx UNUSED,
229 + void *data)
230 {
231 struct bundle_list *list = data;
232 return bundle_list_update(key, value, list);
@@ -871,7 +873,9 @@ cached:
873 return advertise_bundle_uri;
874 }
875
874 -static int config_to_packet_line(const char *key, const char *value, void *data)
876 +static int config_to_packet_line(const char *key, const char *value,
877 + const struct config_context *ctx UNUSED,
878 + void *data)
879 {
880 struct packet_reader *writer = data;
881
compat/mingw.c
+2 -1
@@ -244,7 +244,8 @@ static int core_restrict_inherited_handles = -1;
244 static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
245 static char *unset_environment_variables;
246
247 -int mingw_core_config(const char *var, const char *value, void *cb)
247 +int mingw_core_config(const char *var, const char *value,
248 + const struct config_context *ctx, void *cb)
249 {
250 if (!strcmp(var, "core.hidedotfiles")) {
251 if (value && !strcasecmp(value, "dotgitonly"))
compat/mingw.h
+3 -1
@@ -11,7 +11,9 @@ typedef _sigset_t sigset_t;
11 #undef _POSIX_THREAD_SAFE_FUNCTIONS
12 #endif
13
14 -int mingw_core_config(const char *var, const char *value, void *cb);
14 +struct config_context;
15 +int mingw_core_config(const char *var, const char *value,
16 + const struct config_context *ctx, void *cb);
17 #define platform_core_config mingw_core_config
18
19 /*
config.c
+24 -14
@@ -209,7 +209,8 @@ struct config_include_data {
209 };
210 #define CONFIG_INCLUDE_INIT { 0 }
211
212 -static int git_config_include(const char *var, const char *value, void *data);
212 +static int git_config_include(const char *var, const char *value,
213 + const struct config_context *ctx, void *data);
214
215 #define MAX_INCLUDE_DEPTH 10
216 static const char include_depth_advice[] = N_(
@@ -388,7 +389,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
389 return ret;
390 }
391
391 -static int add_remote_url(const char *var, const char *value, void *data)
392 +static int add_remote_url(const char *var, const char *value,
393 + const struct config_context *ctx UNUSED, void *data)
394 {
395 struct string_list *remote_urls = data;
396 const char *remote_name;
@@ -423,6 +425,7 @@ static void populate_remote_urls(struct config_include_data *inc)
425 }
426
427 static int forbid_remote_url(const char *var, const char *value UNUSED,
428 + const struct config_context *ctx UNUSED,
429 void *data UNUSED)
430 {
431 const char *remote_name;
@@ -486,7 +489,9 @@ static int include_condition_is_true(struct config_source *cs,
489 return 0;
490 }
491
489 -static int git_config_include(const char *var, const char *value, void *data)
492 +static int git_config_include(const char *var, const char *value,
493 + const struct config_context *ctx,
494 + void *data)
495 {
496 struct config_include_data *inc = data;
497 struct config_source *cs = inc->config_reader->source;
@@ -498,7 +503,7 @@ static int git_config_include(const char *var, const char *value, void *data)
503 * Pass along all values, including "include" directives; this makes it
504 * possible to query information on the includes themselves.
505 */
501 - ret = inc->fn(var, value, inc->data);
506 + ret = inc->fn(var, value, NULL, inc->data);
507 if (ret < 0)
508 return ret;
509
@@ -680,7 +685,7 @@ static int config_parse_pair(const char *key, const char *value,
685 if (git_config_parse_key(key, &canonical_name, NULL))
686 return -1;
687
683 - ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
688 + ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0;
689 free(canonical_name);
690 return ret;
691 }
@@ -968,7 +973,7 @@ static int get_value(struct config_source *cs, config_fn_t fn, void *data,
973 * accurate line number in error messages.
974 */
975 cs->linenr--;
971 - ret = fn(name->buf, value, data);
976 + ret = fn(name->buf, value, NULL, data);
977 if (ret >= 0)
978 cs->linenr++;
979 return ret;
@@ -1562,7 +1567,8 @@ int git_config_color(char *dest, const char *var, const char *value)
1567 return 0;
1568 }
1569
1565 -static int git_default_core_config(const char *var, const char *value, void *cb)
1570 +static int git_default_core_config(const char *var, const char *value,
1571 + const struct config_context *ctx, void *cb)
1572 {
1573 /* This needs a better name */
1574 if (!strcmp(var, "core.filemode")) {
@@ -1842,7 +1848,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
1848 }
1849
1850 /* Add other config variables here and to Documentation/config.txt. */
1845 - return platform_core_config(var, value, cb);
1851 + return platform_core_config(var, value, ctx, cb);
1852 }
1853
1854 static int git_default_sparse_config(const char *var, const char *value)
@@ -1944,15 +1950,16 @@ static int git_default_mailmap_config(const char *var, const char *value)
1950 return 0;
1951 }
1952
1947 -int git_default_config(const char *var, const char *value, void *cb)
1953 +int git_default_config(const char *var, const char *value,
1954 + const struct config_context *ctx, void *cb)
1955 {
1956 if (starts_with(var, "core."))
1950 - return git_default_core_config(var, value, cb);
1957 + return git_default_core_config(var, value, ctx, cb);
1958
1959 if (starts_with(var, "user.") ||
1960 starts_with(var, "author.") ||
1961 starts_with(var, "committer."))
1955 - return git_ident_config(var, value, cb);
1962 + return git_ident_config(var, value, ctx, cb);
1963
1964 if (starts_with(var, "i18n."))
1965 return git_default_i18n_config(var, value);
@@ -2318,7 +2325,7 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
2325
2326 config_reader_set_kvi(reader, values->items[value_index].util);
2327
2321 - if (fn(entry->key, values->items[value_index].string, data) < 0)
2328 + if (fn(entry->key, values->items[value_index].string, NULL, data) < 0)
2329 git_die_config_linenr(entry->key,
2330 reader->config_kvi->filename,
2331 reader->config_kvi->linenr);
@@ -2496,7 +2503,9 @@ struct configset_add_data {
2503 };
2504 #define CONFIGSET_ADD_INIT { 0 }
2505
2499 -static int config_set_callback(const char *key, const char *value, void *cb)
2506 +static int config_set_callback(const char *key, const char *value,
2507 + const struct config_context *ctx UNUSED,
2508 + void *cb)
2509 {
2510 struct configset_add_data *data = cb;
2511 configset_add_value(data->config_reader, data->config_set, key, value);
@@ -3106,7 +3115,8 @@ static int store_aux_event(enum config_event_t type,
3115 return 0;
3116 }
3117
3109 -static int store_aux(const char *key, const char *value, void *cb)
3118 +static int store_aux(const char *key, const char *value,
3119 + const struct config_context *ctx UNUSED, void *cb)
3120 {
3121 struct config_store_data *store = cb;
3122
config.h
+31 -10
@@ -110,8 +110,29 @@ struct config_options {
110 } error_action;
111 };
112
113 +/* Config source metadata for a given config key-value pair */
114 +struct key_value_info {
115 + const char *filename;
116 + int linenr;
117 + enum config_origin_type origin_type;
118 + enum config_scope scope;
119 +};
120 +#define KVI_INIT { \
121 + .filename = NULL, \
122 + .linenr = -1, \
123 + .origin_type = CONFIG_ORIGIN_UNKNOWN, \
124 + .scope = CONFIG_SCOPE_UNKNOWN, \
125 +}
126 +
127 +/* Captures additional information that a config callback can use. */
128 +struct config_context {
129 + /* Config source metadata for key and value. */
130 + const struct key_value_info *kvi;
131 +};
132 +#define CONFIG_CONTEXT_INIT { 0 }
133 +
134 /**
114 - * A config callback function takes three parameters:
135 + * A config callback function takes four parameters:
136 *
137 * - the name of the parsed variable. This is in canonical "flat" form: the
138 * section, subsection, and variable segments will be separated by dots,
@@ -122,15 +143,22 @@ struct config_options {
143 * value specified, the value will be NULL (typically this means it
144 * should be interpreted as boolean true).
145 *
146 + * - the 'config context', that is, additional information about the config
147 + * iteration operation provided by the config machinery. For example, this
148 + * includes information about the config source being parsed (e.g. the
149 + * filename).
150 + *
151 * - a void pointer passed in by the caller of the config API; this can
152 * contain callback-specific data
153 *
154 * A config callback should return 0 for success, or -1 if the variable
155 * could not be parsed properly.
156 */
131 -typedef int (*config_fn_t)(const char *, const char *, void *);
157 +typedef int (*config_fn_t)(const char *, const char *,
158 + const struct config_context *, void *);
159
133 -int git_default_config(const char *, const char *, void *);
160 +int git_default_config(const char *, const char *,
161 + const struct config_context *, void *);
162
163 /**
164 * Read a specific file in git-config format.
@@ -667,13 +695,6 @@ int git_config_get_expiry(const char *key, const char **output);
695 /* parse either "this many days" integer, or "5.days.ago" approxidate */
696 int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
697
670 -struct key_value_info {
671 - const char *filename;
672 - int linenr;
673 - enum config_origin_type origin_type;
674 - enum config_scope scope;
675 -};
676 -
698 /**
699 * First prints the error message specified by the caller in `err` and then
700 * dies printing the line number and the file name of the highest priority
connect.c
+2 -2
@@ -964,7 +964,7 @@ static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
964 static char *git_proxy_command;
965
966 static int git_proxy_command_options(const char *var, const char *value,
967 - void *cb)
967 + const struct config_context *ctx, void *cb)
968 {
969 if (!strcmp(var, "core.gitproxy")) {
970 const char *for_pos;
@@ -1010,7 +1010,7 @@ static int git_proxy_command_options(const char *var, const char *value,
1010 return 0;
1011 }
1012
1013 - return git_default_config(var, value, cb);
1013 + return git_default_config(var, value, ctx, cb);
1014 }
1015
1016 static int git_use_proxy(const char *host)
contrib/coccinelle/config_fn_ctx.pending.cocci new
+144
@@ -0,0 +1,144 @@
1 +@ get_fn @
2 +identifier fn, R;
3 +@@
4 +(
5 +(
6 +git_config_from_file
7 +|
8 +git_config_from_file_with_options
9 +|
10 +git_config_from_mem
11 +|
12 +git_config_from_blob_oid
13 +|
14 +read_early_config
15 +|
16 +read_very_early_config
17 +|
18 +config_with_options
19 +|
20 +git_config
21 +|
22 +git_protected_config
23 +|
24 +config_from_gitmodules
25 +)
26 + (fn, ...)
27 +|
28 +repo_config(R, fn, ...)
29 +)
30 +
31 +@ extends get_fn @
32 +identifier C1, C2, D;
33 +@@
34 +int fn(const char *C1, const char *C2,
35 ++ const struct config_context *ctx,
36 + void *D);
37 +
38 +@ extends get_fn @
39 +@@
40 +int fn(const char *, const char *,
41 ++ const struct config_context *,
42 + void *);
43 +
44 +@ extends get_fn @
45 +// Don't change fns that look like callback fns but aren't
46 +identifier fn2 != tar_filter_config && != git_diff_heuristic_config &&
47 + != git_default_submodule_config && != git_color_config &&
48 + != bundle_list_update && != parse_object_filter_config;
49 +identifier C1, C2, D1, D2, S;
50 +attribute name UNUSED;
51 +@@
52 +int fn(const char *C1, const char *C2,
53 ++ const struct config_context *ctx,
54 + void *D1) {
55 +<+...
56 +(
57 +fn2(C1, C2
58 ++ , ctx
59 +, D2);
60 +|
61 +if(fn2(C1, C2
62 ++ , ctx
63 +, D2) < 0) { ... }
64 +|
65 +return fn2(C1, C2
66 ++ , ctx
67 +, D2);
68 +|
69 +S = fn2(C1, C2
70 ++ , ctx
71 +, D2);
72 +)
73 +...+>
74 + }
75 +
76 +@ extends get_fn@
77 +identifier C1, C2, D;
78 +attribute name UNUSED;
79 +@@
80 +int fn(const char *C1, const char *C2,
81 ++ const struct config_context *ctx UNUSED,
82 + void *D) {...}
83 +
84 +
85 +// The previous rules don't catch all callbacks, especially if they're defined
86 +// in a separate file from the git_config() call. Fix these manually.
87 +@@
88 +identifier C1, C2, D;
89 +attribute name UNUSED;
90 +@@
91 +int
92 +(
93 +git_ident_config
94 +|
95 +urlmatch_collect_fn
96 +|
97 +write_one_config
98 +|
99 +forbid_remote_url
100 +|
101 +credential_config_callback
102 +)
103 + (const char *C1, const char *C2,
104 ++ const struct config_context *ctx UNUSED,
105 + void *D) {...}
106 +
107 +@@
108 +identifier C1, C2, D, D2, S, fn2;
109 +@@
110 +int
111 +(
112 +http_options
113 +|
114 +git_status_config
115 +|
116 +git_commit_config
117 +|
118 +git_default_core_config
119 +|
120 +grep_config
121 +)
122 + (const char *C1, const char *C2,
123 ++ const struct config_context *ctx,
124 + void *D) {
125 +<+...
126 +(
127 +fn2(C1, C2
128 ++ , ctx
129 +, D2);
130 +|
131 +if(fn2(C1, C2
132 ++ , ctx
133 +, D2) < 0) { ... }
134 +|
135 +return fn2(C1, C2
136 ++ , ctx
137 +, D2);
138 +|
139 +S = fn2(C1, C2
140 ++ , ctx
141 +, D2);
142 +)
143 +...+>
144 + }
convert.c
+3 -1
@@ -1015,7 +1015,9 @@ static int apply_filter(const char *path, const char *src, size_t len,
1015 return 0;
1016 }
1017
1018 -static int read_convert_config(const char *var, const char *value, void *cb UNUSED)
1018 +static int read_convert_config(const char *var, const char *value,
1019 + const struct config_context *ctx UNUSED,
1020 + void *cb UNUSED)
1021 {
1022 const char *key, *name;
1023 size_t namelen;
credential.c
+1
@@ -49,6 +49,7 @@ static int credential_from_potentially_partial_url(struct credential *c,
49 const char *url);
50
51 static int credential_config_callback(const char *var, const char *value,
52 + const struct config_context *ctx UNUSED,
53 void *data)
54 {
55 struct credential *c = data;
delta-islands.c
+3 -1
@@ -341,7 +341,9 @@ static void free_remote_islands(kh_str_t *remote_islands)
341 kh_destroy_str(remote_islands);
342 }
343
344 -static int island_config_callback(const char *k, const char *v, void *cb)
344 +static int island_config_callback(const char *k, const char *v,
345 + const struct config_context *ctx UNUSED,
346 + void *cb)
347 {
348 struct island_load_data *ild = cb;
349
diff.c
+6 -4
@@ -357,7 +357,8 @@ static unsigned parse_color_moved_ws(const char *arg)
357 return ret;
358 }
359
360 -int git_diff_ui_config(const char *var, const char *value, void *cb)
360 +int git_diff_ui_config(const char *var, const char *value,
361 + const struct config_context *ctx, void *cb)
362 {
363 if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
364 diff_use_color_default = git_config_colorbool(var, value);
@@ -440,10 +441,11 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
441 if (git_color_config(var, value, cb) < 0)
442 return -1;
443
443 - return git_diff_basic_config(var, value, cb);
444 + return git_diff_basic_config(var, value, ctx, cb);
445 }
446
446 -int git_diff_basic_config(const char *var, const char *value, void *cb)
447 +int git_diff_basic_config(const char *var, const char *value,
448 + const struct config_context *ctx, void *cb)
449 {
450 const char *name;
451
@@ -495,7 +497,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
497 if (git_diff_heuristic_config(var, value, cb) < 0)
498 return -1;
499
498 - return git_default_config(var, value, cb);
500 + return git_default_config(var, value, ctx, cb);
501 }
502
503 static char *quote_two(const char *one, const char *two)
diff.h
+5 -2
@@ -531,10 +531,13 @@ void free_diffstat_info(struct diffstat_t *diffstat);
531 int parse_long_opt(const char *opt, const char **argv,
532 const char **optarg);
533
534 -int git_diff_basic_config(const char *var, const char *value, void *cb);
534 +struct config_context;
535 +int git_diff_basic_config(const char *var, const char *value,
536 + const struct config_context *ctx, void *cb);
537 int git_diff_heuristic_config(const char *var, const char *value, void *cb);
538 void init_diff_ui_defaults(void);
537 -int git_diff_ui_config(const char *var, const char *value, void *cb);
539 +int git_diff_ui_config(const char *var, const char *value,
540 + const struct config_context *ctx, void *cb);
541 void repo_diff_setup(struct repository *, struct diff_options *);
542 struct option *add_diff_options(const struct option *, struct diff_options *);
543 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
fetch-pack.c
+3 -2
@@ -1860,7 +1860,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1860 return ref;
1861 }
1862
1863 -static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
1863 +static int fetch_pack_config_cb(const char *var, const char *value,
1864 + const struct config_context *ctx, void *cb)
1865 {
1866 if (strcmp(var, "fetch.fsck.skiplist") == 0) {
1867 const char *path;
@@ -1882,7 +1883,7 @@ static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
1883 return 0;
1884 }
1885
1885 - return git_default_config(var, value, cb);
1886 + return git_default_config(var, value, ctx, cb);
1887 }
1888
1889 static void fetch_pack_config(void)
fmt-merge-msg.c
+3 -2
@@ -20,7 +20,8 @@ static int use_branch_desc;
20 static int suppress_dest_pattern_seen;
21 static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP;
22
23 -int fmt_merge_msg_config(const char *key, const char *value, void *cb)
23 +int fmt_merge_msg_config(const char *key, const char *value,
24 + const struct config_context *ctx, void *cb)
25 {
26 if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
27 int is_bool;
@@ -40,7 +41,7 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb)
41 string_list_append(&suppress_dest_patterns, value);
42 suppress_dest_pattern_seen = 1;
43 } else {
43 - return git_default_config(key, value, cb);
44 + return git_default_config(key, value, ctx, cb);
45 }
46 return 0;
47 }
fmt-merge-msg.h
+2 -1
@@ -13,7 +13,8 @@ struct fmt_merge_msg_opts {
13 };
14
15 extern int merge_log_config;
16 -int fmt_merge_msg_config(const char *key, const char *value, void *cb);
16 +int fmt_merge_msg_config(const char *key, const char *value,
17 + const struct config_context *ctx, void *cb);
18 int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
19 struct fmt_merge_msg_opts *);
20
fsck.c
+6 -3
@@ -1163,7 +1163,9 @@ struct fsck_gitmodules_data {
1163 int ret;
1164 };
1165
1166 -static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
1166 +static int fsck_gitmodules_fn(const char *var, const char *value,
1167 + const struct config_context *ctx UNUSED,
1168 + void *vdata)
1169 {
1170 struct fsck_gitmodules_data *data = vdata;
1171 const char *subsection, *key;
@@ -1373,7 +1375,8 @@ int fsck_finish(struct fsck_options *options)
1375 return ret;
1376 }
1377
1376 -int git_fsck_config(const char *var, const char *value, void *cb)
1378 +int git_fsck_config(const char *var, const char *value,
1379 + const struct config_context *ctx, void *cb)
1380 {
1381 struct fsck_options *options = cb;
1382 if (strcmp(var, "fsck.skiplist") == 0) {
@@ -1394,7 +1397,7 @@ int git_fsck_config(const char *var, const char *value, void *cb)
1397 return 0;
1398 }
1399
1397 - return git_default_config(var, value, cb);
1400 + return git_default_config(var, value, ctx, cb);
1401 }
1402
1403 /*
fsck.h
+3 -1
@@ -233,10 +233,12 @@ void fsck_put_object_name(struct fsck_options *options,
233 const char *fsck_describe_object(struct fsck_options *options,
234 const struct object_id *oid);
235
236 +struct key_value_info;
237 /*
238 * git_config() callback for use by fsck-y tools that want to support
239 * fsck.<msg> fsck.skipList etc.
240 */
240 -int git_fsck_config(const char *var, const char *value, void *cb);
241 +int git_fsck_config(const char *var, const char *value,
242 + const struct config_context *ctx, void *cb);
243
244 #endif
git-compat-util.h
+2
@@ -440,8 +440,10 @@ typedef uintmax_t timestamp_t;
440 #endif
441
442 #ifndef platform_core_config
443 +struct config_context;
444 static inline int noop_core_config(const char *var UNUSED,
445 const char *value UNUSED,
446 + const struct config_context *ctx UNUSED,
447 void *cb UNUSED)
448 {
449 return 0;
gpg-interface.c
+5 -2
@@ -14,7 +14,8 @@
14 #include "alias.h"
15 #include "wrapper.h"
16
17 -static int git_gpg_config(const char *, const char *, void *);
17 +static int git_gpg_config(const char *, const char *,
18 + const struct config_context *, void *);
19
20 static void gpg_interface_lazy_init(void)
21 {
@@ -720,7 +721,9 @@ void set_signing_key(const char *key)
721 configured_signing_key = xstrdup(key);
722 }
723
723 -static int git_gpg_config(const char *var, const char *value, void *cb UNUSED)
724 +static int git_gpg_config(const char *var, const char *value,
725 + const struct config_context *ctx UNUSED,
726 + void *cb UNUSED)
727 {
728 struct gpg_format *fmt = NULL;
729 char *fmtname = NULL;
grep.c
+4 -3
@@ -56,7 +56,8 @@ define_list_config_array_extra(color_grep_slots, {"match"});
56 * Read the configuration file once and store it in
57 * the grep_defaults template.
58 */
59 -int grep_config(const char *var, const char *value, void *cb)
59 +int grep_config(const char *var, const char *value,
60 + const struct config_context *ctx, void *cb)
61 {
62 struct grep_opt *opt = cb;
63 const char *slot;
@@ -91,9 +92,9 @@ int grep_config(const char *var, const char *value, void *cb)
92 if (!strcmp(var, "color.grep"))
93 opt->color = git_config_colorbool(var, value);
94 if (!strcmp(var, "color.grep.match")) {
94 - if (grep_config("color.grep.matchcontext", value, cb) < 0)
95 + if (grep_config("color.grep.matchcontext", value, ctx, cb) < 0)
96 return -1;
96 - if (grep_config("color.grep.matchselected", value, cb) < 0)
97 + if (grep_config("color.grep.matchselected", value, ctx, cb) < 0)
98 return -1;
99 } else if (skip_prefix(var, "color.grep.", &slot)) {
100 int i = LOOKUP_CONFIG(color_grep_slots, slot);
grep.h
+3 -1
@@ -202,7 +202,9 @@ struct grep_opt {
202 .output = std_output, \
203 }
204
205 -int grep_config(const char *var, const char *value, void *);
205 +struct config_context;
206 +int grep_config(const char *var, const char *value,
207 + const struct config_context *ctx, void *data);
208 void grep_init(struct grep_opt *, struct repository *repo);
209
210 void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
help.c
+5 -2
@@ -309,7 +309,8 @@ void load_command_list(const char *prefix,
309 exclude_cmds(other_cmds, main_cmds);
310 }
311
312 -static int get_colopts(const char *var, const char *value, void *data)
312 +static int get_colopts(const char *var, const char *value,
313 + const struct config_context *ctx UNUSED, void *data)
314 {
315 unsigned int *colopts = data;
316
@@ -459,7 +460,8 @@ void list_developer_interfaces_help(void)
460 putchar('\n');
461 }
462
462 -static int get_alias(const char *var, const char *value, void *data)
463 +static int get_alias(const char *var, const char *value,
464 + const struct config_context *ctx UNUSED, void *data)
465 {
466 struct string_list *list = data;
467
@@ -543,6 +545,7 @@ static struct cmdnames aliases;
545 #define AUTOCORRECT_IMMEDIATELY (-1)
546
547 static int git_unknown_cmd_config(const char *var, const char *value,
548 + const struct config_context *ctx UNUSED,
549 void *cb UNUSED)
550 {
551 const char *p;
http.c
+3 -2
@@ -363,7 +363,8 @@ static void process_curl_messages(void)
363 }
364 }
365
366 -static int http_options(const char *var, const char *value, void *cb)
366 +static int http_options(const char *var, const char *value,
367 + const struct config_context *ctx, void *data)
368 {
369 if (!strcmp("http.version", var)) {
370 return git_config_string(&curl_http_version, var, value);
@@ -534,7 +535,7 @@ static int http_options(const char *var, const char *value, void *cb)
535 }
536
537 /* Fall back on the default ones */
537 - return git_default_config(var, value, cb);
538 + return git_default_config(var, value, ctx, data);
539 }
540
541 static int curl_empty_auth_enabled(void)
ident.c
+3 -1
@@ -671,7 +671,9 @@ static int set_ident(const char *var, const char *value)
671 return 0;
672 }
673
674 -int git_ident_config(const char *var, const char *value, void *data UNUSED)
674 +int git_ident_config(const char *var, const char *value,
675 + const struct config_context *ctx UNUSED,
676 + void *data UNUSED)
677 {
678 if (!strcmp(var, "user.useconfigonly")) {
679 ident_use_config_only = git_config_bool(var, value);
ident.h
+3 -1
@@ -62,6 +62,8 @@ const char *fmt_name(enum want_ident);
62 int committer_ident_sufficiently_given(void);
63 int author_ident_sufficiently_given(void);
64
65 -int git_ident_config(const char *, const char *, void *);
65 +struct config_context;
66 +int git_ident_config(const char *, const char *, const struct config_context *,
67 + void *);
68
69 #endif
imap-send.c
+3 -2
@@ -1323,7 +1323,8 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
1323 return 1;
1324 }
1325
1326 -static int git_imap_config(const char *var, const char *val, void *cb)
1326 +static int git_imap_config(const char *var, const char *val,
1327 + const struct config_context *ctx, void *cb)
1328 {
1329
1330 if (!strcmp("imap.sslverify", var))
@@ -1357,7 +1358,7 @@ static int git_imap_config(const char *var, const char *val, void *cb)
1358 server.host = xstrdup(val);
1359 }
1360 } else
1360 - return git_default_config(var, val, cb);
1361 + return git_default_config(var, val, ctx, cb);
1362
1363 return 0;
1364 }
ll-merge.c
+1
@@ -254,6 +254,7 @@ static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
254 static const char *default_ll_merge;
255
256 static int read_merge_config(const char *var, const char *value,
257 + const struct config_context *ctx UNUSED,
258 void *cb UNUSED)
259 {
260 struct ll_merge_driver *fn;
ls-refs.c
+1
@@ -137,6 +137,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data)
137 }
138
139 static int ls_refs_config(const char *var, const char *value,
140 + const struct config_context *ctx UNUSED,
141 void *cb_data)
142 {
143 struct ls_refs_data *data = cb_data;
mailinfo.c
+3 -2
@@ -1241,12 +1241,13 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
1241 return 0;
1242 }
1243
1244 -static int git_mailinfo_config(const char *var, const char *value, void *mi_)
1244 +static int git_mailinfo_config(const char *var, const char *value,
1245 + const struct config_context *ctx, void *mi_)
1246 {
1247 struct mailinfo *mi = mi_;
1248
1249 if (!starts_with(var, "mailinfo."))
1249 - return git_default_config(var, value, NULL);
1250 + return git_default_config(var, value, ctx, NULL);
1251 if (!strcmp(var, "mailinfo.scissors")) {
1252 mi->use_scissors = git_config_bool(var, value);
1253 return 0;
notes-utils.c
+3 -1
@@ -94,7 +94,9 @@ static combine_notes_fn parse_combine_notes_fn(const char *v)
94 return NULL;
95 }
96
97 -static int notes_rewrite_config(const char *k, const char *v, void *cb)
97 +static int notes_rewrite_config(const char *k, const char *v,
98 + const struct config_context *ctx UNUSED,
99 + void *cb)
100 {
101 struct notes_rewrite_cfg *c = cb;
102 if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
notes.c
+3 -1
@@ -974,7 +974,9 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
974 free(globs_copy);
975 }
976
977 -static int notes_display_config(const char *k, const char *v, void *cb)
977 +static int notes_display_config(const char *k, const char *v,
978 + const struct config_context *ctx UNUSED,
979 + void *cb)
980 {
981 int *load_refs = cb;
982
pager.c
+4 -1
@@ -43,6 +43,7 @@ static void wait_for_pager_signal(int signo)
43 }
44
45 static int core_pager_config(const char *var, const char *value,
46 + const struct config_context *ctx UNUSED,
47 void *data UNUSED)
48 {
49 if (!strcmp(var, "core.pager"))
@@ -228,7 +229,9 @@ struct pager_command_config_data {
229 char *value;
230 };
231
231 -static int pager_command_config(const char *var, const char *value, void *vdata)
232 +static int pager_command_config(const char *var, const char *value,
233 + const struct config_context *ctx UNUSED,
234 + void *vdata)
235 {
236 struct pager_command_config_data *data = vdata;
237 const char *cmd;
pretty.c
+1
@@ -56,6 +56,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
56 }
57
58 static int git_pretty_formats_config(const char *var, const char *value,
59 + const struct config_context *ctx UNUSED,
60 void *cb UNUSED)
61 {
62 struct cmt_fmt_map *commit_format = NULL;
promisor-remote.c
+3 -1
@@ -100,7 +100,9 @@ static void promisor_remote_move_to_tail(struct promisor_remote_config *config,
100 config->promisors_tail = &r->next;
101 }
102
103 -static int promisor_remote_config(const char *var, const char *value, void *data)
103 +static int promisor_remote_config(const char *var, const char *value,
104 + const struct config_context *ctx UNUSED,
105 + void *data)
106 {
107 struct promisor_remote_config *config = data;
108 const char *name;
remote.c
+2 -1
@@ -349,7 +349,8 @@ static void read_branches_file(struct remote_state *remote_state,
349 remote->fetch_tags = 1; /* always auto-follow */
350 }
351
352 -static int handle_config(const char *key, const char *value, void *cb)
352 +static int handle_config(const char *key, const char *value,
353 + const struct config_context *ctx UNUSED, void *cb)
354 {
355 const char *name;
356 size_t namelen;
revision.c
+3 -1
@@ -1572,7 +1572,9 @@ struct exclude_hidden_refs_cb {
1572 const char *section;
1573 };
1574
1575 -static int hide_refs_config(const char *var, const char *value, void *cb_data)
1575 +static int hide_refs_config(const char *var, const char *value,
1576 + const struct config_context *ctx UNUSED,
1577 + void *cb_data)
1578 {
1579 struct exclude_hidden_refs_cb *cb = cb_data;
1580 cb->exclusions->hidden_refs_configured = 1;
scalar.c
+3 -1
@@ -594,7 +594,9 @@ static int cmd_register(int argc, const char **argv)
594 return register_dir();
595 }
596
597 -static int get_scalar_repos(const char *key, const char *value, void *data)
597 +static int get_scalar_repos(const char *key, const char *value,
598 + const struct config_context *ctx UNUSED,
599 + void *data)
600 {
601 struct string_list *list = data;
602
sequencer.c
+6 -3
@@ -219,7 +219,8 @@ static struct update_ref_record *init_update_ref_record(const char *ref)
219 return rec;
220 }
221
222 -static int git_sequencer_config(const char *k, const char *v, void *cb)
222 +static int git_sequencer_config(const char *k, const char *v,
223 + const struct config_context *ctx, void *cb)
224 {
225 struct replay_opts *opts = cb;
226 int status;
@@ -274,7 +275,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
275 if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference"))
276 opts->commit_use_reference = git_config_bool(k, v);
277
277 - return git_diff_basic_config(k, v, NULL);
278 + return git_diff_basic_config(k, v, ctx, NULL);
279 }
280
281 void sequencer_init_config(struct replay_opts *opts)
@@ -2881,7 +2882,9 @@ static int git_config_string_dup(char **dest,
2882 return 0;
2883 }
2884
2884 -static int populate_opts_cb(const char *key, const char *value, void *data)
2885 +static int populate_opts_cb(const char *key, const char *value,
2886 + const struct config_context *ctx UNUSED,
2887 + void *data)
2888 {
2889 struct replay_opts *opts = data;
2890 int error_flag = 1;
setup.c
+11 -5
@@ -517,7 +517,9 @@ no_prevention_needed:
517 startup_info->original_cwd = NULL;
518 }
519
520 -static int read_worktree_config(const char *var, const char *value, void *vdata)
520 +static int read_worktree_config(const char *var, const char *value,
521 + const struct config_context *ctx UNUSED,
522 + void *vdata)
523 {
524 struct repository_format *data = vdata;
525
@@ -588,7 +590,8 @@ static enum extension_result handle_extension(const char *var,
590 return EXTENSION_UNKNOWN;
591 }
592
591 -static int check_repo_format(const char *var, const char *value, void *vdata)
593 +static int check_repo_format(const char *var, const char *value,
594 + const struct config_context *ctx, void *vdata)
595 {
596 struct repository_format *data = vdata;
597 const char *ext;
@@ -617,7 +620,7 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
620 }
621 }
622
620 - return read_worktree_config(var, value, vdata);
623 + return read_worktree_config(var, value, ctx, vdata);
624 }
625
626 static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
@@ -1115,7 +1118,8 @@ struct safe_directory_data {
1118 int is_safe;
1119 };
1120
1118 -static int safe_directory_cb(const char *key, const char *value, void *d)
1121 +static int safe_directory_cb(const char *key, const char *value,
1122 + const struct config_context *ctx UNUSED, void *d)
1123 {
1124 struct safe_directory_data *data = d;
1125
@@ -1171,7 +1175,9 @@ static int ensure_valid_ownership(const char *gitfile,
1175 return data.is_safe;
1176 }
1177
1174 -static int allowed_bare_repo_cb(const char *key, const char *value, void *d)
1178 +static int allowed_bare_repo_cb(const char *key, const char *value,
1179 + const struct config_context *ctx UNUSED,
1180 + void *d)
1181 {
1182 enum allowed_bare_repo *allowed_bare_repo = d;
1183
submodule-config.c
+12 -5
@@ -426,7 +426,8 @@ struct parse_config_parameter {
426 * config store (.git/config, etc). Callers are responsible for
427 * checking for overrides in the main config store when appropriate.
428 */
429 -static int parse_config(const char *var, const char *value, void *data)
429 +static int parse_config(const char *var, const char *value,
430 + const struct config_context *ctx UNUSED, void *data)
431 {
432 struct parse_config_parameter *me = data;
433 struct submodule *submodule;
@@ -674,7 +675,8 @@ out:
675 }
676 }
677
677 -static int gitmodules_cb(const char *var, const char *value, void *data)
678 +static int gitmodules_cb(const char *var, const char *value,
679 + const struct config_context *ctx, void *data)
680 {
681 struct repository *repo = data;
682 struct parse_config_parameter parameter;
@@ -684,7 +686,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
686 parameter.gitmodules_oid = null_oid();
687 parameter.overwrite = 1;
688
687 - return parse_config(var, value, &parameter);
689 + return parse_config(var, value, ctx, &parameter);
690 }
691
692 void repo_read_gitmodules(struct repository *repo, int skip_if_read)
@@ -801,7 +803,9 @@ void submodule_free(struct repository *r)
803 submodule_cache_clear(r->submodule_cache);
804 }
805
804 -static int config_print_callback(const char *var, const char *value, void *cb_data)
806 +static int config_print_callback(const char *var, const char *value,
807 + const struct config_context *ctx UNUSED,
808 + void *cb_data)
809 {
810 char *wanted_key = cb_data;
811
@@ -843,7 +847,9 @@ struct fetch_config {
847 int *recurse_submodules;
848 };
849
846 -static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
850 +static int gitmodules_fetch_config(const char *var, const char *value,
851 + const struct config_context *ctx UNUSED,
852 + void *cb)
853 {
854 struct fetch_config *config = cb;
855 if (!strcmp(var, "submodule.fetchjobs")) {
@@ -871,6 +877,7 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
877 }
878
879 static int gitmodules_update_clone_config(const char *var, const char *value,
880 + const struct config_context *ctx UNUSED,
881 void *cb)
882 {
883 int *max_jobs = cb;
t/helper/test-config.c
+8 -3
@@ -42,7 +42,9 @@
42 *
43 */
44
45 -static int iterate_cb(const char *var, const char *value, void *data UNUSED)
45 +static int iterate_cb(const char *var, const char *value,
46 + const struct config_context *ctx UNUSED,
47 + void *data UNUSED)
48 {
49 static int nr;
50
@@ -59,7 +61,8 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED)
61 return 0;
62 }
63
62 -static int parse_int_cb(const char *var, const char *value, void *data)
64 +static int parse_int_cb(const char *var, const char *value,
65 + const struct config_context *ctx UNUSED, void *data)
66 {
67 const char *key_to_match = data;
68
@@ -70,7 +73,9 @@ static int parse_int_cb(const char *var, const char *value, void *data)
73 return 0;
74 }
75
73 -static int early_config_cb(const char *var, const char *value, void *vdata)
76 +static int early_config_cb(const char *var, const char *value,
77 + const struct config_context *ctx UNUSED,
78 + void *vdata)
79 {
80 const char *key = vdata;
81
t/helper/test-userdiff.c
+3 -1
@@ -12,7 +12,9 @@ static int driver_cb(struct userdiff_driver *driver,
12 return 0;
13 }
14
15 -static int cmd__userdiff_config(const char *var, const char *value, void *cb UNUSED)
15 +static int cmd__userdiff_config(const char *var, const char *value,
16 + const struct config_context *ctx UNUSED,
17 + void *cb UNUSED)
18 {
19 if (userdiff_config(var, value) < 0)
20 return -1;
trace2/tr2_cfg.c
+7 -2
@@ -99,7 +99,8 @@ struct tr2_cfg_data {
99 /*
100 * See if the given config key matches any of our patterns of interest.
101 */
102 -static int tr2_cfg_cb(const char *key, const char *value, void *d)
102 +static int tr2_cfg_cb(const char *key, const char *value,
103 + const struct config_context *ctx UNUSED, void *d)
104 {
105 struct strbuf **s;
106 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
@@ -142,8 +143,12 @@ void tr2_list_env_vars_fl(const char *file, int line)
143 void tr2_cfg_set_fl(const char *file, int line, const char *key,
144 const char *value)
145 {
146 + struct key_value_info kvi = KVI_INIT;
147 + struct config_context ctx = {
148 + .kvi = &kvi,
149 + };
150 struct tr2_cfg_data data = { file, line };
151
152 if (tr2_cfg_load_patterns() > 0)
148 - tr2_cfg_cb(key, value, &data);
153 + tr2_cfg_cb(key, value, &ctx, &data);
154 }
trace2/tr2_sysenv.c
+2 -1
@@ -57,7 +57,8 @@ static struct tr2_sysenv_entry tr2_sysenv_settings[] = {
57 };
58 /* clang-format on */
59
60 -static int tr2_sysenv_cb(const char *key, const char *value, void *d)
60 +static int tr2_sysenv_cb(const char *key, const char *value,
61 + const struct config_context *ctx UNUSED, void *d)
62 {
63 int k;
64
trailer.c
+2
@@ -482,6 +482,7 @@ static struct {
482 };
483
484 static int git_trailer_default_config(const char *conf_key, const char *value,
485 + const struct config_context *ctx UNUSED,
486 void *cb UNUSED)
487 {
488 const char *trailer_item, *variable_name;
@@ -514,6 +515,7 @@ static int git_trailer_default_config(const char *conf_key, const char *value,
515 }
516
517 static int git_trailer_config(const char *conf_key, const char *value,
518 + const struct config_context *ctx UNUSED,
519 void *cb UNUSED)
520 {
521 const char *trailer_item, *variable_name;
upload-pack.c
+6 -2
@@ -1309,7 +1309,9 @@ static int parse_object_filter_config(const char *var, const char *value,
1309 return 0;
1310 }
1311
1312 -static int upload_pack_config(const char *var, const char *value, void *cb_data)
1312 +static int upload_pack_config(const char *var, const char *value,
1313 + const struct config_context *ctx UNUSED,
1314 + void *cb_data)
1315 {
1316 struct upload_pack_data *data = cb_data;
1317
@@ -1350,7 +1352,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
1352 return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
1353 }
1354
1353 -static int upload_pack_protected_config(const char *var, const char *value, void *cb_data)
1355 +static int upload_pack_protected_config(const char *var, const char *value,
1356 + const struct config_context *ctx UNUSED,
1357 + void *cb_data)
1358 {
1359 struct upload_pack_data *data = cb_data;
1360
urlmatch.c
+4 -3
@@ -551,7 +551,8 @@ static int cmp_matches(const struct urlmatch_item *a,
551 return 0;
552 }
553
554 -int urlmatch_config_entry(const char *var, const char *value, void *cb)
554 +int urlmatch_config_entry(const char *var, const char *value,
555 + const struct config_context *ctx, void *cb)
556 {
557 struct string_list_item *item;
558 struct urlmatch_config *collect = cb;
@@ -565,7 +566,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
566
567 if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') {
568 if (collect->cascade_fn)
568 - return collect->cascade_fn(var, value, cb);
569 + return collect->cascade_fn(var, value, ctx, cb);
570 return 0; /* not interested */
571 }
572 dot = strrchr(key, '.');
@@ -609,7 +610,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
610 strbuf_addstr(&synthkey, collect->section);
611 strbuf_addch(&synthkey, '.');
612 strbuf_addstr(&synthkey, key);
612 - retval = collect->collect_fn(synthkey.buf, value, collect->cb);
613 + retval = collect->collect_fn(synthkey.buf, value, ctx, collect->cb);
614
615 strbuf_release(&synthkey);
616 return retval;
urlmatch.h
+2 -1
@@ -71,7 +71,8 @@ struct urlmatch_config {
71 .vars = STRING_LIST_INIT_DUP, \
72 }
73
74 -int urlmatch_config_entry(const char *var, const char *value, void *cb);
74 +int urlmatch_config_entry(const char *var, const char *value,
75 + const struct config_context *ctx, void *cb);
76 void urlmatch_config_release(struct urlmatch_config *config);
77
78 #endif /* URL_MATCH_H */
xdiff-interface.c
+3 -2
@@ -307,7 +307,8 @@ int xdiff_compare_lines(const char *l1, long s1,
307
308 int git_xmerge_style = -1;
309
310 -int git_xmerge_config(const char *var, const char *value, void *cb)
310 +int git_xmerge_config(const char *var, const char *value,
311 + const struct config_context *ctx, void *cb)
312 {
313 if (!strcmp(var, "merge.conflictstyle")) {
314 if (!value)
@@ -327,5 +328,5 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
328 value, var);
329 return 0;
330 }
330 - return git_default_config(var, value, cb);
331 + return git_default_config(var, value, ctx, cb);
332 }
xdiff-interface.h
+3 -1
@@ -50,7 +50,9 @@ int buffer_is_binary(const char *ptr, unsigned long size);
50
51 void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
52 void xdiff_clear_find_func(xdemitconf_t *xecfg);
53 -int git_xmerge_config(const char *var, const char *value, void *cb);
53 +struct config_context;
54 +int git_xmerge_config(const char *var, const char *value,
55 + const struct config_context *ctx, void *cb);
56 extern int git_xmerge_style;
57
58 /*