Git fork

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>

authored by

Glen Choo and committed by
Junio C Hamano
a4e7e317 e0f9a51c

+515 -181
+2 -1
alias.c
··· 12 struct string_list *list; 13 }; 14 15 - static int config_alias_cb(const char *key, const char *value, void *d) 16 { 17 struct config_alias_data *data = d; 18 const char *p;
··· 12 struct string_list *list; 13 }; 14 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;
+2 -1
archive-tar.c
··· 411 return 0; 412 } 413 414 - static int git_tar_config(const char *var, const char *value, void *cb) 415 { 416 if (!strcmp(var, "tar.umask")) { 417 if (value && !strcmp(value, "user")) {
··· 411 return 0; 412 } 413 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")) {
+1
archive-zip.c
··· 617 } 618 619 static int archive_zip_config(const char *var, const char *value, 620 void *data UNUSED) 621 { 622 return userdiff_config(var, value);
··· 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);
+3 -2
builtin/add.c
··· 357 OPT_END(), 358 }; 359 360 - static int add_config(const char *var, const char *value, void *cb) 361 { 362 if (!strcmp(var, "add.ignoreerrors") || 363 !strcmp(var, "add.ignore-errors")) { ··· 368 if (git_color_config(var, value, cb) < 0) 369 return -1; 370 371 - return git_default_config(var, value, cb); 372 } 373 374 static const char embedded_advice[] = N_(
··· 357 OPT_END(), 358 }; 359 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")) { ··· 369 if (git_color_config(var, value, cb) < 0) 370 return -1; 371 372 + return git_default_config(var, value, ctx, cb); 373 } 374 375 static const char embedded_advice[] = N_(
+3 -2
builtin/blame.c
··· 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) 698 { 699 if (!strcmp(var, "blame.showroot")) { 700 show_root = git_config_bool(var, value); ··· 767 if (userdiff_config(var, value) < 0) 768 return -1; 769 770 - return git_default_config(var, value, cb); 771 } 772 773 static int blame_copy_callback(const struct option *option, const char *arg, int unset)
··· 694 return prefix_path(prefix, prefix ? strlen(prefix) : 0, path); 695 } 696 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); ··· 768 if (userdiff_config(var, value) < 0) 769 return -1; 770 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)
+3 -2
builtin/branch.c
··· 83 84 define_list_config_array(color_branch_slots); 85 86 - static int git_branch_config(const char *var, const char *value, void *cb) 87 { 88 const char *slot_name; 89 ··· 120 if (git_color_config(var, value, cb) < 0) 121 return -1; 122 123 - return git_default_config(var, value, cb); 124 } 125 126 static const char *branch_get_color(enum color_branch ix)
··· 83 84 define_list_config_array(color_branch_slots); 85 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 ··· 121 if (git_color_config(var, value, cb) < 0) 122 return -1; 123 124 + return git_default_config(var, value, ctx, cb); 125 } 126 127 static const char *branch_get_color(enum color_branch ix)
+3 -2
builtin/cat-file.c
··· 873 return retval; 874 } 875 876 - static int git_cat_file_config(const char *var, const char *value, void *cb) 877 { 878 if (userdiff_config(var, value) < 0) 879 return -1; 880 881 - return git_default_config(var, value, cb); 882 } 883 884 static int batch_option_callback(const struct option *opt,
··· 873 return retval; 874 } 875 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 882 + return git_default_config(var, value, ctx, cb); 883 } 884 885 static int batch_option_callback(const struct option *opt,
+9 -3
builtin/checkout.c
··· 1186 return ret || writeout_error; 1187 } 1188 1189 - static int git_checkout_config(const char *var, const char *value, void *cb) 1190 { 1191 struct checkout_opts *opts = cb; 1192 ··· 1202 if (starts_with(var, "submodule.")) 1203 return git_default_submodule_config(var, value, NULL); 1204 1205 - return git_xmerge_config(var, value, NULL); 1206 } 1207 1208 static void setup_new_branch_info_and_source_tree( ··· 1689 } 1690 1691 if (opts->conflict_style) { 1692 opts->merge = 1; /* implied */ 1693 - git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL); 1694 } 1695 if (opts->force) { 1696 opts->discard_changes = 1;
··· 1186 return ret || writeout_error; 1187 } 1188 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 ··· 1203 if (starts_with(var, "submodule.")) 1204 return git_default_submodule_config(var, value, NULL); 1205 1206 + return git_xmerge_config(var, value, ctx, NULL); 1207 } 1208 1209 static void setup_new_branch_info_and_source_tree( ··· 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 */ 1698 + git_xmerge_config("merge.conflictstyle", opts->conflict_style, 1699 + &ctx, NULL); 1700 } 1701 if (opts->force) { 1702 opts->discard_changes = 1;
+3 -2
builtin/clean.c
··· 103 104 define_list_config_array(color_interactive_slots); 105 106 - static int git_clean_config(const char *var, const char *value, void *cb) 107 { 108 const char *slot_name; 109 ··· 133 if (git_color_config(var, value, cb) < 0) 134 return -1; 135 136 - return git_default_config(var, value, cb); 137 } 138 139 static const char *clean_get_color(enum color_clean ix)
··· 103 104 define_list_config_array(color_interactive_slots); 105 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 ··· 134 if (git_color_config(var, value, cb) < 0) 135 return -1; 136 137 + return git_default_config(var, value, ctx, cb); 138 } 139 140 static const char *clean_get_color(enum color_clean ix)
+7 -4
builtin/clone.c
··· 790 return err; 791 } 792 793 - static int git_clone_config(const char *k, const char *v, void *cb) 794 { 795 if (!strcmp(k, "clone.defaultremotename")) { 796 free(remote_name); ··· 801 if (!strcmp(k, "clone.filtersubmodules")) 802 config_filter_submodules = git_config_bool(k, v); 803 804 - return git_default_config(k, v, cb); 805 } 806 807 - static int write_one_config(const char *key, const char *value, void *data) 808 { 809 /* 810 * give git_clone_config a chance to write config values back to the 811 * environment, since git_config_set_multivar_gently only deals with 812 * config-file writes 813 */ 814 - int apply_failed = git_clone_config(key, value, data); 815 if (apply_failed) 816 return apply_failed; 817
··· 790 return err; 791 } 792 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); ··· 802 if (!strcmp(k, "clone.filtersubmodules")) 803 config_filter_submodules = git_config_bool(k, v); 804 805 + return git_default_config(k, v, ctx, cb); 806 } 807 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 */ 817 + int apply_failed = git_clone_config(key, value, ctx, data); 818 if (apply_failed) 819 return apply_failed; 820
+2 -1
builtin/column.c
··· 13 }; 14 static unsigned int colopts; 15 16 - static int column_config(const char *var, const char *value, void *cb) 17 { 18 return git_column_config(var, value, cb, &colopts); 19 }
··· 13 }; 14 static unsigned int colopts; 15 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 }
+1
builtin/commit-graph.c
··· 186 } 187 188 static int git_commit_graph_write_config(const char *var, const char *value, 189 void *cb UNUSED) 190 { 191 if (!strcmp(var, "commitgraph.maxnewfilters"))
··· 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"))
+6 -4
builtin/commit.c
··· 1405 return LOOKUP_CONFIG(color_status_slots, slot); 1406 } 1407 1408 - static int git_status_config(const char *k, const char *v, void *cb) 1409 { 1410 struct wt_status *s = cb; 1411 const char *slot_name; ··· 1490 s->detect_rename = git_config_rename(k, v); 1491 return 0; 1492 } 1493 - return git_diff_ui_config(k, v, NULL); 1494 } 1495 1496 int cmd_status(int argc, const char **argv, const char *prefix) ··· 1605 return 0; 1606 } 1607 1608 - static int git_commit_config(const char *k, const char *v, void *cb) 1609 { 1610 struct wt_status *s = cb; 1611 ··· 1627 return 0; 1628 } 1629 1630 - return git_status_config(k, v, s); 1631 } 1632 1633 int cmd_commit(int argc, const char **argv, const char *prefix)
··· 1405 return LOOKUP_CONFIG(color_status_slots, slot); 1406 } 1407 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; ··· 1491 s->detect_rename = git_config_rename(k, v); 1492 return 0; 1493 } 1494 + return git_diff_ui_config(k, v, ctx, NULL); 1495 } 1496 1497 int cmd_status(int argc, const char **argv, const char *prefix) ··· 1606 return 0; 1607 } 1608 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 ··· 1629 return 0; 1630 } 1631 1632 + return git_status_config(k, v, ctx, s); 1633 } 1634 1635 int cmd_commit(int argc, const char **argv, const char *prefix)
+8 -2
builtin/config.c
··· 217 } 218 219 static int show_all_config(const char *key_, const char *value_, 220 void *cb UNUSED) 221 { 222 if (show_origin || show_scope) { ··· 301 return 0; 302 } 303 304 - static int collect_config(const char *key_, const char *value_, void *cb) 305 { 306 struct strbuf_list *values = cb; 307 ··· 470 static char parsed_color[COLOR_MAXLEN]; 471 472 static int git_get_color_config(const char *var, const char *value, 473 void *cb UNUSED) 474 { 475 if (!strcmp(var, get_color_slot)) { ··· 503 static int get_diff_color_found; 504 static int get_color_ui_found; 505 static int git_get_colorbool_config(const char *var, const char *value, 506 void *data UNUSED) 507 { 508 if (!strcmp(var, get_colorbool_slot)) ··· 561 struct strbuf value; 562 }; 563 564 - static int urlmatch_collect_fn(const char *var, const char *value, void *cb) 565 { 566 struct string_list *values = cb; 567 struct string_list_item *item = string_list_insert(values, var);
··· 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) { ··· 302 return 0; 303 } 304 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 ··· 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)) { ··· 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)) ··· 565 struct strbuf value; 566 }; 567 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);
+3 -2
builtin/difftool.c
··· 40 NULL 41 }; 42 43 - static int difftool_config(const char *var, const char *value, void *cb) 44 { 45 if (!strcmp(var, "difftool.trustexitcode")) { 46 trust_exit_code = git_config_bool(var, value); 47 return 0; 48 } 49 50 - return git_default_config(var, value, cb); 51 } 52 53 static int print_tool_help(void)
··· 40 NULL 41 }; 42 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 51 + return git_default_config(var, value, ctx, cb); 52 } 53 54 static int print_tool_help(void)
+6 -3
builtin/fetch.c
··· 110 int submodule_fetch_jobs; 111 }; 112 113 - static int git_fetch_config(const char *k, const char *v, void *cb) 114 { 115 struct fetch_config *fetch_config = cb; 116 ··· 164 "fetch.output", v); 165 } 166 167 - return git_default_config(k, v, cb); 168 } 169 170 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset) ··· 1799 struct string_list *list; 1800 }; 1801 1802 - static int get_remote_group(const char *key, const char *value, void *priv) 1803 { 1804 struct remote_group_data *g = priv; 1805
··· 110 int submodule_fetch_jobs; 111 }; 112 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 ··· 165 "fetch.output", v); 166 } 167 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) ··· 1800 struct string_list *list; 1801 }; 1802 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
+3 -2
builtin/fsmonitor--daemon.c
··· 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) 41 { 42 if (!strcmp(var, FSMONITOR__IPC_THREADS)) { 43 int i = git_config_int(var, value); ··· 67 return 0; 68 } 69 70 - return git_default_config(var, value, cb); 71 } 72 73 /*
··· 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, 41 + const struct config_context *ctx, void *cb) 42 { 43 if (!strcmp(var, FSMONITOR__IPC_THREADS)) { 44 int i = git_config_int(var, value); ··· 68 return 0; 69 } 70 71 + return git_default_config(var, value, ctx, cb); 72 } 73 74 /*
+4 -3
builtin/grep.c
··· 290 return hit; 291 } 292 293 - static int grep_cmd_config(const char *var, const char *value, void *cb) 294 { 295 - int st = grep_config(var, value, cb); 296 297 if (git_color_config(var, value, cb) < 0) 298 st = -1; 299 - else if (git_default_config(var, value, cb) < 0) 300 st = -1; 301 302 if (!strcmp(var, "grep.threads")) {
··· 290 return hit; 291 } 292 293 + static int grep_cmd_config(const char *var, const char *value, 294 + const struct config_context *ctx, void *cb) 295 { 296 + int st = grep_config(var, value, ctx, cb); 297 298 if (git_color_config(var, value, cb) < 0) 299 st = -1; 300 + else if (git_default_config(var, value, ctx, cb) < 0) 301 st = -1; 302 303 if (!strcmp(var, "grep.threads")) {
+3 -2
builtin/help.c
··· 398 return 0; 399 } 400 401 - static int git_help_config(const char *var, const char *value, void *cb) 402 { 403 if (!strcmp(var, "help.format")) { 404 if (!value) ··· 421 if (starts_with(var, "man.")) 422 return add_man_viewer_info(var, value); 423 424 - return git_default_config(var, value, cb); 425 } 426 427 static struct cmdnames main_cmds, other_cmds;
··· 398 return 0; 399 } 400 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) ··· 422 if (starts_with(var, "man.")) 423 return add_man_viewer_info(var, value); 424 425 + return git_default_config(var, value, ctx, cb); 426 } 427 428 static struct cmdnames main_cmds, other_cmds;
+3 -2
builtin/index-pack.c
··· 1581 strbuf_release(&pack_name); 1582 } 1583 1584 - static int git_index_pack_config(const char *k, const char *v, void *cb) 1585 { 1586 struct pack_idx_option *opts = cb; 1587 ··· 1608 else 1609 opts->flags &= ~WRITE_REV; 1610 } 1611 - return git_default_config(k, v, cb); 1612 } 1613 1614 static int cmp_uint32(const void *a_, const void *b_)
··· 1581 strbuf_release(&pack_name); 1582 } 1583 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 ··· 1609 else 1610 opts->flags &= ~WRITE_REV; 1611 } 1612 + return git_default_config(k, v, ctx, cb); 1613 } 1614 1615 static int cmp_uint32(const void *a_, const void *b_)
+6 -4
builtin/log.c
··· 564 return retval; 565 } 566 567 - static int git_log_config(const char *var, const char *value, void *cb) 568 { 569 const char *slot_name; 570 ··· 613 return 0; 614 } 615 616 - return git_diff_ui_config(var, value, cb); 617 } 618 619 int cmd_whatchanged(int argc, const char **argv, const char *prefix) ··· 979 die(_("%s: invalid cover from description mode"), arg); 980 } 981 982 - static int git_format_config(const char *var, const char *value, void *cb) 983 { 984 if (!strcmp(var, "format.headers")) { 985 if (!value) ··· 1108 if (!strcmp(var, "diff.noprefix")) 1109 return 0; 1110 1111 - return git_log_config(var, value, cb); 1112 } 1113 1114 static const char *output_directory = NULL;
··· 564 return retval; 565 } 566 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 ··· 614 return 0; 615 } 616 617 + return git_diff_ui_config(var, value, ctx, cb); 618 } 619 620 int cmd_whatchanged(int argc, const char **argv, const char *prefix) ··· 980 die(_("%s: invalid cover from description mode"), arg); 981 } 982 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) ··· 1110 if (!strcmp(var, "diff.noprefix")) 1111 return 0; 1112 1113 + return git_log_config(var, value, ctx, cb); 1114 } 1115 1116 static const char *output_directory = NULL;
+4 -3
builtin/merge.c
··· 623 free(argv); 624 } 625 626 - static int git_merge_config(const char *k, const char *v, void *cb) 627 { 628 int status; 629 const char *str; ··· 668 return 0; 669 } 670 671 - status = fmt_merge_msg_config(k, v, cb); 672 if (status) 673 return status; 674 - return git_diff_ui_config(k, v, cb); 675 } 676 677 static int read_tree_trivial(struct object_id *common, struct object_id *head,
··· 623 free(argv); 624 } 625 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; ··· 669 return 0; 670 } 671 672 + status = fmt_merge_msg_config(k, v, ctx, cb); 673 if (status) 674 return status; 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,
+1
builtin/multi-pack-index.c
··· 82 } 83 84 static int git_multi_pack_index_write_config(const char *var, const char *value, 85 void *cb UNUSED) 86 { 87 if (!strcmp(var, "pack.writebitmaphashcache")) {
··· 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")) {
+3 -2
builtin/pack-objects.c
··· 3135 free(delta_list); 3136 } 3137 3138 - static int git_pack_config(const char *k, const char *v, void *cb) 3139 { 3140 if (!strcmp(k, "pack.window")) { 3141 window = git_config_int(k, v); ··· 3227 ex->uri = xstrdup(pack_end + 1); 3228 oidmap_put(&configured_exclusions, ex); 3229 } 3230 - return git_default_config(k, v, cb); 3231 } 3232 3233 /* Counters for trace2 output when in --stdin-packs mode. */
··· 3135 free(delta_list); 3136 } 3137 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); ··· 3228 ex->uri = xstrdup(pack_end + 1); 3229 oidmap_put(&configured_exclusions, ex); 3230 } 3231 + return git_default_config(k, v, ctx, cb); 3232 } 3233 3234 /* Counters for trace2 output when in --stdin-packs mode. */
+3 -2
builtin/patch-id.c
··· 196 int verbatim; 197 }; 198 199 - static int git_patch_id_config(const char *var, const char *value, void *cb) 200 { 201 struct patch_id_opts *opts = cb; 202 ··· 209 return 0; 210 } 211 212 - return git_default_config(var, value, cb); 213 } 214 215 int cmd_patch_id(int argc, const char **argv, const char *prefix)
··· 196 int verbatim; 197 }; 198 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 ··· 210 return 0; 211 } 212 213 + return git_default_config(var, value, ctx, cb); 214 } 215 216 int cmd_patch_id(int argc, const char **argv, const char *prefix)
+3 -2
builtin/pull.c
··· 361 /** 362 * Read config variables. 363 */ 364 - static int git_pull_config(const char *var, const char *value, void *cb) 365 { 366 if (!strcmp(var, "rebase.autostash")) { 367 config_autostash = git_config_bool(var, value); ··· 374 check_trust_level = 0; 375 } 376 377 - return git_default_config(var, value, cb); 378 } 379 380 /**
··· 361 /** 362 * Read config variables. 363 */ 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); ··· 375 check_trust_level = 0; 376 } 377 378 + return git_default_config(var, value, ctx, cb); 379 } 380 381 /**
+3 -2
builtin/push.c
··· 510 } 511 512 513 - static int git_push_config(const char *k, const char *v, void *cb) 514 { 515 const char *slot_name; 516 int *flags = cb; ··· 577 return 0; 578 } 579 580 - return git_default_config(k, v, NULL); 581 } 582 583 int cmd_push(int argc, const char **argv, const char *prefix)
··· 510 } 511 512 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; ··· 578 return 0; 579 } 580 581 + return git_default_config(k, v, ctx, NULL); 582 } 583 584 int cmd_push(int argc, const char **argv, const char *prefix)
+3 -2
builtin/read-tree.c
··· 102 return 0; 103 } 104 105 - static int git_read_tree_config(const char *var, const char *value, void *cb) 106 { 107 if (!strcmp(var, "submodule.recurse")) 108 return git_default_submodule_config(var, value, cb); 109 110 - return git_default_config(var, value, cb); 111 } 112 113 int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
··· 102 return 0; 103 } 104 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 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)
+3 -2
builtin/rebase.c
··· 772 die(_("Unknown rebase-merges mode: %s"), value); 773 } 774 775 - static int rebase_config(const char *var, const char *value, void *data) 776 { 777 struct rebase_options *opts = data; 778 ··· 831 return git_config_string(&opts->default_backend, var, value); 832 } 833 834 - return git_default_config(var, value, data); 835 } 836 837 static int checkout_up_to_date(struct rebase_options *options)
··· 772 die(_("Unknown rebase-merges mode: %s"), value); 773 } 774 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 ··· 832 return git_config_string(&opts->default_backend, var, value); 833 } 834 835 + return git_default_config(var, value, ctx, data); 836 } 837 838 static int checkout_up_to_date(struct rebase_options *options)
+3 -2
builtin/receive-pack.c
··· 139 return DENY_IGNORE; 140 } 141 142 - static int receive_pack_config(const char *var, const char *value, void *cb) 143 { 144 int status = parse_hide_refs_config(var, value, "receive", &hidden_refs); 145 ··· 266 return 0; 267 } 268 269 - return git_default_config(var, value, cb); 270 } 271 272 static void show_ref(const char *path, const struct object_id *oid)
··· 139 return DENY_IGNORE; 140 } 141 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 ··· 267 return 0; 268 } 269 270 + return git_default_config(var, value, ctx, cb); 271 } 272 273 static void show_ref(const char *path, const struct object_id *oid)
+4 -3
builtin/reflog.c
··· 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) 112 { 113 const char *pattern, *key; 114 size_t pattern_len; ··· 117 struct reflog_expire_cfg *ent; 118 119 if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0) 120 - return git_default_config(var, value, cb); 121 122 if (!strcmp(key, "reflogexpire")) { 123 slot = EXPIRE_TOTAL; ··· 128 if (git_config_expiry_date(&expire, var, value)) 129 return -1; 130 } else 131 - return git_default_config(var, value, cb); 132 133 if (!pattern) { 134 switch (slot) {
··· 108 #define EXPIRE_TOTAL 01 109 #define EXPIRE_UNREACH 02 110 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; ··· 118 struct reflog_expire_cfg *ent; 119 120 if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0) 121 + return git_default_config(var, value, ctx, cb); 122 123 if (!strcmp(key, "reflogexpire")) { 124 slot = EXPIRE_TOTAL; ··· 129 if (git_config_expiry_date(&expire, var, value)) 130 return -1; 131 } else 132 + return git_default_config(var, value, ctx, cb); 133 134 if (!pattern) { 135 switch (slot) {
+5 -2
builtin/remote.c
··· 268 #define abbrev_branch(name) abbrev_ref((name), "refs/heads/") 269 270 static int config_read_branches(const char *key, const char *value, 271 void *data UNUSED) 272 { 273 const char *orig_key = key; ··· 645 }; 646 647 static int config_read_push_default(const char *key, const char *value, 648 - void *cb) 649 { 650 struct push_default_info* info = cb; 651 if (strcmp(key, "remote.pushdefault") || ··· 1494 return result; 1495 } 1496 1497 - static int get_remote_default(const char *key, const char *value UNUSED, void *priv) 1498 { 1499 if (strcmp(key, "remotes.default") == 0) { 1500 int *found = priv;
··· 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; ··· 646 }; 647 648 static int config_read_push_default(const char *key, const char *value, 649 + const struct config_context *ctx UNUSED, void *cb) 650 { 651 struct push_default_info* info = cb; 652 if (strcmp(key, "remote.pushdefault") || ··· 1495 return result; 1496 } 1497 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;
+3 -2
builtin/repack.c
··· 59 int local; 60 }; 61 62 - static int repack_config(const char *var, const char *value, void *cb) 63 { 64 struct pack_objects_args *cruft_po_args = cb; 65 if (!strcmp(var, "repack.usedeltabaseoffset")) { ··· 91 return git_config_string(&cruft_po_args->depth, var, value); 92 if (!strcmp(var, "repack.cruftthreads")) 93 return git_config_string(&cruft_po_args->threads, var, value); 94 - return git_default_config(var, value, cb); 95 } 96 97 /*
··· 59 int local; 60 }; 61 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")) { ··· 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); 95 + return git_default_config(var, value, ctx, cb); 96 } 97 98 /*
+3 -2
builtin/reset.c
··· 312 return update_ref_status; 313 } 314 315 - static int git_reset_config(const char *var, const char *value, void *cb) 316 { 317 if (!strcmp(var, "submodule.recurse")) 318 return git_default_submodule_config(var, value, cb); 319 320 - return git_default_config(var, value, cb); 321 } 322 323 int cmd_reset(int argc, const char **argv, const char *prefix)
··· 312 return update_ref_status; 313 } 314 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 321 + return git_default_config(var, value, ctx, cb); 322 } 323 324 int cmd_reset(int argc, const char **argv, const char *prefix)
+3 -2
builtin/send-pack.c
··· 131 strbuf_release(&buf); 132 } 133 134 - static int send_pack_config(const char *k, const char *v, void *cb) 135 { 136 if (!strcmp(k, "push.gpgsign")) { 137 const char *value; ··· 151 } 152 } 153 } 154 - return git_default_config(k, v, cb); 155 } 156 157 int cmd_send_pack(int argc, const char **argv, const char *prefix)
··· 131 strbuf_release(&buf); 132 } 133 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; ··· 152 } 153 } 154 } 155 + return git_default_config(k, v, ctx, cb); 156 } 157 158 int cmd_send_pack(int argc, const char **argv, const char *prefix)
+3 -2
builtin/show-branch.c
··· 559 die("bad sha1 reference %s", av); 560 } 561 562 - static int git_show_branch_config(const char *var, const char *value, void *cb) 563 { 564 if (!strcmp(var, "showbranch.default")) { 565 if (!value) ··· 582 if (git_color_config(var, value, cb) < 0) 583 return -1; 584 585 - return git_default_config(var, value, cb); 586 } 587 588 static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
··· 559 die("bad sha1 reference %s", av); 560 } 561 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) ··· 583 if (git_color_config(var, value, cb) < 0) 584 return -1; 585 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)
+3 -2
builtin/stash.c
··· 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) 841 { 842 if (!strcmp(var, "stash.showstat")) { 843 show_stat = git_config_bool(var, value); ··· 851 show_include_untracked = git_config_bool(var, value); 852 return 0; 853 } 854 - return git_diff_basic_config(var, value, cb); 855 } 856 857 static void diff_include_untracked(const struct stash_info *info, struct diff_options *diff_opt)
··· 837 static int show_patch; 838 static int show_include_untracked; 839 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); ··· 852 show_include_untracked = git_config_bool(var, value); 853 return 0; 854 } 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)
+1
builtin/submodule--helper.c
··· 2192 } 2193 2194 static int git_update_clone_config(const char *var, const char *value, 2195 void *cb) 2196 { 2197 int *max_jobs = cb;
··· 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;
+3 -2
builtin/tag.c
··· 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) 192 { 193 if (!strcmp(var, "tag.gpgsign")) { 194 config_sign_tag = git_config_bool(var, value); ··· 213 if (git_color_config(var, value, cb) < 0) 214 return -1; 215 216 - return git_default_config(var, value, cb); 217 } 218 219 static void write_tag_body(int fd, const struct object_id *oid)
··· 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, 192 + const struct config_context *ctx, void *cb) 193 { 194 if (!strcmp(var, "tag.gpgsign")) { 195 config_sign_tag = git_config_bool(var, value); ··· 214 if (git_color_config(var, value, cb) < 0) 215 return -1; 216 217 + return git_default_config(var, value, ctx, cb); 218 } 219 220 static void write_tag_body(int fd, const struct object_id *oid)
+3 -2
builtin/var.c
··· 71 return NULL; 72 } 73 74 - static int show_config(const char *var, const char *value, void *cb) 75 { 76 if (value) 77 printf("%s=%s\n", var, value); 78 else 79 printf("%s\n", var); 80 - return git_default_config(var, value, cb); 81 } 82 83 int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
··· 71 return NULL; 72 } 73 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); 81 + return git_default_config(var, value, ctx, cb); 82 } 83 84 int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
+3 -2
builtin/worktree.c
··· 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) 132 { 133 if (!strcmp(var, "worktree.guessremote")) { 134 guess_remote = git_config_bool(var, value); 135 return 0; 136 } 137 138 - return git_default_config(var, value, cb); 139 } 140 141 static int delete_git_dir(const char *id)
··· 128 static int guess_remote; 129 static timestamp_t expire; 130 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 139 + return git_default_config(var, value, ctx, cb); 140 } 141 142 static int delete_git_dir(const char *id)
+6 -2
bundle-uri.c
··· 224 return 0; 225 } 226 227 - static int config_to_bundle_list(const char *key, const char *value, void *data) 228 { 229 struct bundle_list *list = data; 230 return bundle_list_update(key, value, list); ··· 871 return advertise_bundle_uri; 872 } 873 874 - static int config_to_packet_line(const char *key, const char *value, void *data) 875 { 876 struct packet_reader *writer = data; 877
··· 224 return 0; 225 } 226 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); ··· 873 return advertise_bundle_uri; 874 } 875 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
+2 -1
compat/mingw.c
··· 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) 248 { 249 if (!strcmp(var, "core.hidedotfiles")) { 250 if (value && !strcasecmp(value, "dotgitonly"))
··· 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, 248 + const struct config_context *ctx, void *cb) 249 { 250 if (!strcmp(var, "core.hidedotfiles")) { 251 if (value && !strcasecmp(value, "dotgitonly"))
+3 -1
compat/mingw.h
··· 11 #undef _POSIX_THREAD_SAFE_FUNCTIONS 12 #endif 13 14 - int mingw_core_config(const char *var, const char *value, void *cb); 15 #define platform_core_config mingw_core_config 16 17 /*
··· 11 #undef _POSIX_THREAD_SAFE_FUNCTIONS 12 #endif 13 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 /*
+24 -14
config.c
··· 209 }; 210 #define CONFIG_INCLUDE_INIT { 0 } 211 212 - static int git_config_include(const char *var, const char *value, void *data); 213 214 #define MAX_INCLUDE_DEPTH 10 215 static const char include_depth_advice[] = N_( ··· 388 return ret; 389 } 390 391 - static int add_remote_url(const char *var, const char *value, void *data) 392 { 393 struct string_list *remote_urls = data; 394 const char *remote_name; ··· 423 } 424 425 static int forbid_remote_url(const char *var, const char *value UNUSED, 426 void *data UNUSED) 427 { 428 const char *remote_name; ··· 486 return 0; 487 } 488 489 - static int git_config_include(const char *var, const char *value, void *data) 490 { 491 struct config_include_data *inc = data; 492 struct config_source *cs = inc->config_reader->source; ··· 498 * Pass along all values, including "include" directives; this makes it 499 * possible to query information on the includes themselves. 500 */ 501 - ret = inc->fn(var, value, inc->data); 502 if (ret < 0) 503 return ret; 504 ··· 680 if (git_config_parse_key(key, &canonical_name, NULL)) 681 return -1; 682 683 - ret = (fn(canonical_name, value, data) < 0) ? -1 : 0; 684 free(canonical_name); 685 return ret; 686 } ··· 968 * accurate line number in error messages. 969 */ 970 cs->linenr--; 971 - ret = fn(name->buf, value, data); 972 if (ret >= 0) 973 cs->linenr++; 974 return ret; ··· 1562 return 0; 1563 } 1564 1565 - static int git_default_core_config(const char *var, const char *value, void *cb) 1566 { 1567 /* This needs a better name */ 1568 if (!strcmp(var, "core.filemode")) { ··· 1842 } 1843 1844 /* Add other config variables here and to Documentation/config.txt. */ 1845 - return platform_core_config(var, value, cb); 1846 } 1847 1848 static int git_default_sparse_config(const char *var, const char *value) ··· 1944 return 0; 1945 } 1946 1947 - int git_default_config(const char *var, const char *value, void *cb) 1948 { 1949 if (starts_with(var, "core.")) 1950 - return git_default_core_config(var, value, cb); 1951 1952 if (starts_with(var, "user.") || 1953 starts_with(var, "author.") || 1954 starts_with(var, "committer.")) 1955 - return git_ident_config(var, value, cb); 1956 1957 if (starts_with(var, "i18n.")) 1958 return git_default_i18n_config(var, value); ··· 2318 2319 config_reader_set_kvi(reader, values->items[value_index].util); 2320 2321 - if (fn(entry->key, values->items[value_index].string, data) < 0) 2322 git_die_config_linenr(entry->key, 2323 reader->config_kvi->filename, 2324 reader->config_kvi->linenr); ··· 2496 }; 2497 #define CONFIGSET_ADD_INIT { 0 } 2498 2499 - static int config_set_callback(const char *key, const char *value, void *cb) 2500 { 2501 struct configset_add_data *data = cb; 2502 configset_add_value(data->config_reader, data->config_set, key, value); ··· 3106 return 0; 3107 } 3108 3109 - static int store_aux(const char *key, const char *value, void *cb) 3110 { 3111 struct config_store_data *store = cb; 3112
··· 209 }; 210 #define CONFIG_INCLUDE_INIT { 0 } 211 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_( ··· 389 return ret; 390 } 391 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; ··· 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; ··· 489 return 0; 490 } 491 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; ··· 503 * Pass along all values, including "include" directives; this makes it 504 * possible to query information on the includes themselves. 505 */ 506 + ret = inc->fn(var, value, NULL, inc->data); 507 if (ret < 0) 508 return ret; 509 ··· 685 if (git_config_parse_key(key, &canonical_name, NULL)) 686 return -1; 687 688 + ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0; 689 free(canonical_name); 690 return ret; 691 } ··· 973 * accurate line number in error messages. 974 */ 975 cs->linenr--; 976 + ret = fn(name->buf, value, NULL, data); 977 if (ret >= 0) 978 cs->linenr++; 979 return ret; ··· 1567 return 0; 1568 } 1569 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")) { ··· 1848 } 1849 1850 /* Add other config variables here and to Documentation/config.txt. */ 1851 + return platform_core_config(var, value, ctx, cb); 1852 } 1853 1854 static int git_default_sparse_config(const char *var, const char *value) ··· 1950 return 0; 1951 } 1952 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.")) 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.")) 1962 + return git_ident_config(var, value, ctx, cb); 1963 1964 if (starts_with(var, "i18n.")) 1965 return git_default_i18n_config(var, value); ··· 2325 2326 config_reader_set_kvi(reader, values->items[value_index].util); 2327 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); ··· 2503 }; 2504 #define CONFIGSET_ADD_INIT { 0 } 2505 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); ··· 3115 return 0; 3116 } 3117 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
+31 -10
config.h
··· 110 } error_action; 111 }; 112 113 /** 114 - * A config callback function takes three parameters: 115 * 116 * - the name of the parsed variable. This is in canonical "flat" form: the 117 * section, subsection, and variable segments will be separated by dots, ··· 122 * value specified, the value will be NULL (typically this means it 123 * should be interpreted as boolean true). 124 * 125 * - a void pointer passed in by the caller of the config API; this can 126 * contain callback-specific data 127 * 128 * A config callback should return 0 for success, or -1 if the variable 129 * could not be parsed properly. 130 */ 131 - typedef int (*config_fn_t)(const char *, const char *, void *); 132 133 - int git_default_config(const char *, const char *, void *); 134 135 /** 136 * Read a specific file in git-config format. ··· 666 667 /* parse either "this many days" integer, or "5.days.ago" approxidate */ 668 int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now); 669 - 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 677 /** 678 * First prints the error message specified by the caller in `err` and then
··· 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 /** 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, ··· 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 */ 157 + typedef int (*config_fn_t)(const char *, const char *, 158 + const struct config_context *, void *); 159 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. ··· 694 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 698 /** 699 * First prints the error message specified by the caller in `err` and then
+2 -2
connect.c
··· 964 static char *git_proxy_command; 965 966 static int git_proxy_command_options(const char *var, const char *value, 967 - void *cb) 968 { 969 if (!strcmp(var, "core.gitproxy")) { 970 const char *for_pos; ··· 1010 return 0; 1011 } 1012 1013 - return git_default_config(var, value, cb); 1014 } 1015 1016 static int git_use_proxy(const char *host)
··· 964 static char *git_proxy_command; 965 966 static int git_proxy_command_options(const char *var, const char *value, 967 + const struct config_context *ctx, void *cb) 968 { 969 if (!strcmp(var, "core.gitproxy")) { 970 const char *for_pos; ··· 1010 return 0; 1011 } 1012 1013 + return git_default_config(var, value, ctx, cb); 1014 } 1015 1016 static int git_use_proxy(const char *host)
+144
contrib/coccinelle/config_fn_ctx.pending.cocci
···
··· 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 + }
+3 -1
convert.c
··· 1015 return 0; 1016 } 1017 1018 - static int read_convert_config(const char *var, const char *value, void *cb UNUSED) 1019 { 1020 const char *key, *name; 1021 size_t namelen;
··· 1015 return 0; 1016 } 1017 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;
+1
credential.c
··· 49 const char *url); 50 51 static int credential_config_callback(const char *var, const char *value, 52 void *data) 53 { 54 struct credential *c = data;
··· 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;
+3 -1
delta-islands.c
··· 341 kh_destroy_str(remote_islands); 342 } 343 344 - static int island_config_callback(const char *k, const char *v, void *cb) 345 { 346 struct island_load_data *ild = cb; 347
··· 341 kh_destroy_str(remote_islands); 342 } 343 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
+6 -4
diff.c
··· 357 return ret; 358 } 359 360 - int git_diff_ui_config(const char *var, const char *value, void *cb) 361 { 362 if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) { 363 diff_use_color_default = git_config_colorbool(var, value); ··· 440 if (git_color_config(var, value, cb) < 0) 441 return -1; 442 443 - return git_diff_basic_config(var, value, cb); 444 } 445 446 - int git_diff_basic_config(const char *var, const char *value, void *cb) 447 { 448 const char *name; 449 ··· 495 if (git_diff_heuristic_config(var, value, cb) < 0) 496 return -1; 497 498 - return git_default_config(var, value, cb); 499 } 500 501 static char *quote_two(const char *one, const char *two)
··· 357 return ret; 358 } 359 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); ··· 441 if (git_color_config(var, value, cb) < 0) 442 return -1; 443 444 + return git_diff_basic_config(var, value, ctx, cb); 445 } 446 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 ··· 497 if (git_diff_heuristic_config(var, value, cb) < 0) 498 return -1; 499 500 + return git_default_config(var, value, ctx, cb); 501 } 502 503 static char *quote_two(const char *one, const char *two)
+5 -2
diff.h
··· 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); 535 int git_diff_heuristic_config(const char *var, const char *value, void *cb); 536 void init_diff_ui_defaults(void); 537 - int git_diff_ui_config(const char *var, const char *value, void *cb); 538 void repo_diff_setup(struct repository *, struct diff_options *); 539 struct option *add_diff_options(const struct option *, struct diff_options *); 540 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
··· 531 int parse_long_opt(const char *opt, const char **argv, 532 const char **optarg); 533 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); 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 *);
+3 -2
fetch-pack.c
··· 1860 return ref; 1861 } 1862 1863 - static int fetch_pack_config_cb(const char *var, const char *value, void *cb) 1864 { 1865 if (strcmp(var, "fetch.fsck.skiplist") == 0) { 1866 const char *path; ··· 1882 return 0; 1883 } 1884 1885 - return git_default_config(var, value, cb); 1886 } 1887 1888 static void fetch_pack_config(void)
··· 1860 return ref; 1861 } 1862 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; ··· 1883 return 0; 1884 } 1885 1886 + return git_default_config(var, value, ctx, cb); 1887 } 1888 1889 static void fetch_pack_config(void)
+3 -2
fmt-merge-msg.c
··· 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) 24 { 25 if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { 26 int is_bool; ··· 40 string_list_append(&suppress_dest_patterns, value); 41 suppress_dest_pattern_seen = 1; 42 } else { 43 - return git_default_config(key, value, cb); 44 } 45 return 0; 46 }
··· 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, 24 + const struct config_context *ctx, void *cb) 25 { 26 if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { 27 int is_bool; ··· 41 string_list_append(&suppress_dest_patterns, value); 42 suppress_dest_pattern_seen = 1; 43 } else { 44 + return git_default_config(key, value, ctx, cb); 45 } 46 return 0; 47 }
+2 -1
fmt-merge-msg.h
··· 13 }; 14 15 extern int merge_log_config; 16 - int fmt_merge_msg_config(const char *key, const char *value, void *cb); 17 int fmt_merge_msg(struct strbuf *in, struct strbuf *out, 18 struct fmt_merge_msg_opts *); 19
··· 13 }; 14 15 extern int merge_log_config; 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
+6 -3
fsck.c
··· 1163 int ret; 1164 }; 1165 1166 - static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) 1167 { 1168 struct fsck_gitmodules_data *data = vdata; 1169 const char *subsection, *key; ··· 1373 return ret; 1374 } 1375 1376 - int git_fsck_config(const char *var, const char *value, void *cb) 1377 { 1378 struct fsck_options *options = cb; 1379 if (strcmp(var, "fsck.skiplist") == 0) { ··· 1394 return 0; 1395 } 1396 1397 - return git_default_config(var, value, cb); 1398 } 1399 1400 /*
··· 1163 int ret; 1164 }; 1165 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; ··· 1375 return ret; 1376 } 1377 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) { ··· 1397 return 0; 1398 } 1399 1400 + return git_default_config(var, value, ctx, cb); 1401 } 1402 1403 /*
+3 -1
fsck.h
··· 233 const char *fsck_describe_object(struct fsck_options *options, 234 const struct object_id *oid); 235 236 /* 237 * git_config() callback for use by fsck-y tools that want to support 238 * fsck.<msg> fsck.skipList etc. 239 */ 240 - int git_fsck_config(const char *var, const char *value, void *cb); 241 242 #endif
··· 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 */ 241 + int git_fsck_config(const char *var, const char *value, 242 + const struct config_context *ctx, void *cb); 243 244 #endif
+2
git-compat-util.h
··· 440 #endif 441 442 #ifndef platform_core_config 443 static inline int noop_core_config(const char *var UNUSED, 444 const char *value UNUSED, 445 void *cb UNUSED) 446 { 447 return 0;
··· 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;
+5 -2
gpg-interface.c
··· 14 #include "alias.h" 15 #include "wrapper.h" 16 17 - static int git_gpg_config(const char *, const char *, void *); 18 19 static void gpg_interface_lazy_init(void) 20 { ··· 720 configured_signing_key = xstrdup(key); 721 } 722 723 - static int git_gpg_config(const char *var, const char *value, void *cb UNUSED) 724 { 725 struct gpg_format *fmt = NULL; 726 char *fmtname = NULL;
··· 14 #include "alias.h" 15 #include "wrapper.h" 16 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 { ··· 721 configured_signing_key = xstrdup(key); 722 } 723 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;
+4 -3
grep.c
··· 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) 60 { 61 struct grep_opt *opt = cb; 62 const char *slot; ··· 91 if (!strcmp(var, "color.grep")) 92 opt->color = git_config_colorbool(var, value); 93 if (!strcmp(var, "color.grep.match")) { 94 - if (grep_config("color.grep.matchcontext", value, cb) < 0) 95 return -1; 96 - if (grep_config("color.grep.matchselected", value, cb) < 0) 97 return -1; 98 } else if (skip_prefix(var, "color.grep.", &slot)) { 99 int i = LOOKUP_CONFIG(color_grep_slots, slot);
··· 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, 60 + const struct config_context *ctx, void *cb) 61 { 62 struct grep_opt *opt = cb; 63 const char *slot; ··· 92 if (!strcmp(var, "color.grep")) 93 opt->color = git_config_colorbool(var, value); 94 if (!strcmp(var, "color.grep.match")) { 95 + if (grep_config("color.grep.matchcontext", value, ctx, cb) < 0) 96 return -1; 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);
+3 -1
grep.h
··· 202 .output = std_output, \ 203 } 204 205 - int grep_config(const char *var, const char *value, void *); 206 void grep_init(struct grep_opt *, struct repository *repo); 207 208 void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
··· 202 .output = std_output, \ 203 } 204 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);
+5 -2
help.c
··· 309 exclude_cmds(other_cmds, main_cmds); 310 } 311 312 - static int get_colopts(const char *var, const char *value, void *data) 313 { 314 unsigned int *colopts = data; 315 ··· 459 putchar('\n'); 460 } 461 462 - static int get_alias(const char *var, const char *value, void *data) 463 { 464 struct string_list *list = data; 465 ··· 543 #define AUTOCORRECT_IMMEDIATELY (-1) 544 545 static int git_unknown_cmd_config(const char *var, const char *value, 546 void *cb UNUSED) 547 { 548 const char *p;
··· 309 exclude_cmds(other_cmds, main_cmds); 310 } 311 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 ··· 460 putchar('\n'); 461 } 462 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 ··· 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;
+3 -2
http.c
··· 363 } 364 } 365 366 - static int http_options(const char *var, const char *value, void *cb) 367 { 368 if (!strcmp("http.version", var)) { 369 return git_config_string(&curl_http_version, var, value); ··· 534 } 535 536 /* Fall back on the default ones */ 537 - return git_default_config(var, value, cb); 538 } 539 540 static int curl_empty_auth_enabled(void)
··· 363 } 364 } 365 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); ··· 535 } 536 537 /* Fall back on the default ones */ 538 + return git_default_config(var, value, ctx, data); 539 } 540 541 static int curl_empty_auth_enabled(void)
+3 -1
ident.c
··· 671 return 0; 672 } 673 674 - int git_ident_config(const char *var, const char *value, void *data UNUSED) 675 { 676 if (!strcmp(var, "user.useconfigonly")) { 677 ident_use_config_only = git_config_bool(var, value);
··· 671 return 0; 672 } 673 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);
+3 -1
ident.h
··· 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 *); 66 67 #endif
··· 62 int committer_ident_sufficiently_given(void); 63 int author_ident_sufficiently_given(void); 64 65 + struct config_context; 66 + int git_ident_config(const char *, const char *, const struct config_context *, 67 + void *); 68 69 #endif
+3 -2
imap-send.c
··· 1323 return 1; 1324 } 1325 1326 - static int git_imap_config(const char *var, const char *val, void *cb) 1327 { 1328 1329 if (!strcmp("imap.sslverify", var)) ··· 1357 server.host = xstrdup(val); 1358 } 1359 } else 1360 - return git_default_config(var, val, cb); 1361 1362 return 0; 1363 }
··· 1323 return 1; 1324 } 1325 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)) ··· 1358 server.host = xstrdup(val); 1359 } 1360 } else 1361 + return git_default_config(var, val, ctx, cb); 1362 1363 return 0; 1364 }
+1
ll-merge.c
··· 254 static const char *default_ll_merge; 255 256 static int read_merge_config(const char *var, const char *value, 257 void *cb UNUSED) 258 { 259 struct ll_merge_driver *fn;
··· 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;
+1
ls-refs.c
··· 137 } 138 139 static int ls_refs_config(const char *var, const char *value, 140 void *cb_data) 141 { 142 struct ls_refs_data *data = cb_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;
+3 -2
mailinfo.c
··· 1241 return 0; 1242 } 1243 1244 - static int git_mailinfo_config(const char *var, const char *value, void *mi_) 1245 { 1246 struct mailinfo *mi = mi_; 1247 1248 if (!starts_with(var, "mailinfo.")) 1249 - return git_default_config(var, value, NULL); 1250 if (!strcmp(var, "mailinfo.scissors")) { 1251 mi->use_scissors = git_config_bool(var, value); 1252 return 0;
··· 1241 return 0; 1242 } 1243 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.")) 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;
+3 -1
notes-utils.c
··· 94 return NULL; 95 } 96 97 - static int notes_rewrite_config(const char *k, const char *v, void *cb) 98 { 99 struct notes_rewrite_cfg *c = cb; 100 if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
··· 94 return NULL; 95 } 96 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)) {
+3 -1
notes.c
··· 974 free(globs_copy); 975 } 976 977 - static int notes_display_config(const char *k, const char *v, void *cb) 978 { 979 int *load_refs = cb; 980
··· 974 free(globs_copy); 975 } 976 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
+4 -1
pager.c
··· 43 } 44 45 static int core_pager_config(const char *var, const char *value, 46 void *data UNUSED) 47 { 48 if (!strcmp(var, "core.pager")) ··· 228 char *value; 229 }; 230 231 - static int pager_command_config(const char *var, const char *value, void *vdata) 232 { 233 struct pager_command_config_data *data = vdata; 234 const char *cmd;
··· 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")) ··· 229 char *value; 230 }; 231 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;
+1
pretty.c
··· 56 } 57 58 static int git_pretty_formats_config(const char *var, const char *value, 59 void *cb UNUSED) 60 { 61 struct cmt_fmt_map *commit_format = NULL;
··· 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;
+3 -1
promisor-remote.c
··· 100 config->promisors_tail = &r->next; 101 } 102 103 - static int promisor_remote_config(const char *var, const char *value, void *data) 104 { 105 struct promisor_remote_config *config = data; 106 const char *name;
··· 100 config->promisors_tail = &r->next; 101 } 102 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;
+2 -1
remote.c
··· 349 remote->fetch_tags = 1; /* always auto-follow */ 350 } 351 352 - static int handle_config(const char *key, const char *value, void *cb) 353 { 354 const char *name; 355 size_t namelen;
··· 349 remote->fetch_tags = 1; /* always auto-follow */ 350 } 351 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;
+3 -1
revision.c
··· 1572 const char *section; 1573 }; 1574 1575 - static int hide_refs_config(const char *var, const char *value, void *cb_data) 1576 { 1577 struct exclude_hidden_refs_cb *cb = cb_data; 1578 cb->exclusions->hidden_refs_configured = 1;
··· 1572 const char *section; 1573 }; 1574 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;
+3 -1
scalar.c
··· 594 return register_dir(); 595 } 596 597 - static int get_scalar_repos(const char *key, const char *value, void *data) 598 { 599 struct string_list *list = data; 600
··· 594 return register_dir(); 595 } 596 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
+6 -3
sequencer.c
··· 219 return rec; 220 } 221 222 - static int git_sequencer_config(const char *k, const char *v, void *cb) 223 { 224 struct replay_opts *opts = cb; 225 int status; ··· 274 if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference")) 275 opts->commit_use_reference = git_config_bool(k, v); 276 277 - return git_diff_basic_config(k, v, NULL); 278 } 279 280 void sequencer_init_config(struct replay_opts *opts) ··· 2881 return 0; 2882 } 2883 2884 - static int populate_opts_cb(const char *key, const char *value, void *data) 2885 { 2886 struct replay_opts *opts = data; 2887 int error_flag = 1;
··· 219 return rec; 220 } 221 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; ··· 275 if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference")) 276 opts->commit_use_reference = git_config_bool(k, v); 277 278 + return git_diff_basic_config(k, v, ctx, NULL); 279 } 280 281 void sequencer_init_config(struct replay_opts *opts) ··· 2882 return 0; 2883 } 2884 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;
+11 -5
setup.c
··· 517 startup_info->original_cwd = NULL; 518 } 519 520 - static int read_worktree_config(const char *var, const char *value, void *vdata) 521 { 522 struct repository_format *data = vdata; 523 ··· 588 return EXTENSION_UNKNOWN; 589 } 590 591 - static int check_repo_format(const char *var, const char *value, void *vdata) 592 { 593 struct repository_format *data = vdata; 594 const char *ext; ··· 617 } 618 } 619 620 - return read_worktree_config(var, value, vdata); 621 } 622 623 static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok) ··· 1115 int is_safe; 1116 }; 1117 1118 - static int safe_directory_cb(const char *key, const char *value, void *d) 1119 { 1120 struct safe_directory_data *data = d; 1121 ··· 1171 return data.is_safe; 1172 } 1173 1174 - static int allowed_bare_repo_cb(const char *key, const char *value, void *d) 1175 { 1176 enum allowed_bare_repo *allowed_bare_repo = d; 1177
··· 517 startup_info->original_cwd = NULL; 518 } 519 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 ··· 590 return EXTENSION_UNKNOWN; 591 } 592 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; ··· 620 } 621 } 622 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) ··· 1118 int is_safe; 1119 }; 1120 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 ··· 1175 return data.is_safe; 1176 } 1177 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
+12 -5
submodule-config.c
··· 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) 430 { 431 struct parse_config_parameter *me = data; 432 struct submodule *submodule; ··· 674 } 675 } 676 677 - static int gitmodules_cb(const char *var, const char *value, void *data) 678 { 679 struct repository *repo = data; 680 struct parse_config_parameter parameter; ··· 684 parameter.gitmodules_oid = null_oid(); 685 parameter.overwrite = 1; 686 687 - return parse_config(var, value, &parameter); 688 } 689 690 void repo_read_gitmodules(struct repository *repo, int skip_if_read) ··· 801 submodule_cache_clear(r->submodule_cache); 802 } 803 804 - static int config_print_callback(const char *var, const char *value, void *cb_data) 805 { 806 char *wanted_key = cb_data; 807 ··· 843 int *recurse_submodules; 844 }; 845 846 - static int gitmodules_fetch_config(const char *var, const char *value, void *cb) 847 { 848 struct fetch_config *config = cb; 849 if (!strcmp(var, "submodule.fetchjobs")) { ··· 871 } 872 873 static int gitmodules_update_clone_config(const char *var, const char *value, 874 void *cb) 875 { 876 int *max_jobs = cb;
··· 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, 430 + const struct config_context *ctx UNUSED, void *data) 431 { 432 struct parse_config_parameter *me = data; 433 struct submodule *submodule; ··· 675 } 676 } 677 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; ··· 686 parameter.gitmodules_oid = null_oid(); 687 parameter.overwrite = 1; 688 689 + return parse_config(var, value, ctx, &parameter); 690 } 691 692 void repo_read_gitmodules(struct repository *repo, int skip_if_read) ··· 803 submodule_cache_clear(r->submodule_cache); 804 } 805 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 ··· 847 int *recurse_submodules; 848 }; 849 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")) { ··· 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;
+8 -3
t/helper/test-config.c
··· 42 * 43 */ 44 45 - static int iterate_cb(const char *var, const char *value, void *data UNUSED) 46 { 47 static int nr; 48 ··· 59 return 0; 60 } 61 62 - static int parse_int_cb(const char *var, const char *value, void *data) 63 { 64 const char *key_to_match = data; 65 ··· 70 return 0; 71 } 72 73 - static int early_config_cb(const char *var, const char *value, void *vdata) 74 { 75 const char *key = vdata; 76
··· 42 * 43 */ 44 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 ··· 61 return 0; 62 } 63 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 ··· 73 return 0; 74 } 75 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
+3 -1
t/helper/test-userdiff.c
··· 12 return 0; 13 } 14 15 - static int cmd__userdiff_config(const char *var, const char *value, void *cb UNUSED) 16 { 17 if (userdiff_config(var, value) < 0) 18 return -1;
··· 12 return 0; 13 } 14 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;
+7 -2
trace2/tr2_cfg.c
··· 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) 103 { 104 struct strbuf **s; 105 struct tr2_cfg_data *data = (struct tr2_cfg_data *)d; ··· 142 void tr2_cfg_set_fl(const char *file, int line, const char *key, 143 const char *value) 144 { 145 struct tr2_cfg_data data = { file, line }; 146 147 if (tr2_cfg_load_patterns() > 0) 148 - tr2_cfg_cb(key, value, &data); 149 }
··· 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, 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; ··· 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) 153 + tr2_cfg_cb(key, value, &ctx, &data); 154 }
+2 -1
trace2/tr2_sysenv.c
··· 57 }; 58 /* clang-format on */ 59 60 - static int tr2_sysenv_cb(const char *key, const char *value, void *d) 61 { 62 int k; 63
··· 57 }; 58 /* clang-format on */ 59 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
+2
trailer.c
··· 482 }; 483 484 static int git_trailer_default_config(const char *conf_key, const char *value, 485 void *cb UNUSED) 486 { 487 const char *trailer_item, *variable_name; ··· 514 } 515 516 static int git_trailer_config(const char *conf_key, const char *value, 517 void *cb UNUSED) 518 { 519 const char *trailer_item, *variable_name;
··· 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; ··· 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;
+6 -2
upload-pack.c
··· 1309 return 0; 1310 } 1311 1312 - static int upload_pack_config(const char *var, const char *value, void *cb_data) 1313 { 1314 struct upload_pack_data *data = cb_data; 1315 ··· 1350 return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs); 1351 } 1352 1353 - static int upload_pack_protected_config(const char *var, const char *value, void *cb_data) 1354 { 1355 struct upload_pack_data *data = cb_data; 1356
··· 1309 return 0; 1310 } 1311 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 ··· 1352 return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs); 1353 } 1354 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
+4 -3
urlmatch.c
··· 551 return 0; 552 } 553 554 - int urlmatch_config_entry(const char *var, const char *value, void *cb) 555 { 556 struct string_list_item *item; 557 struct urlmatch_config *collect = cb; ··· 565 566 if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') { 567 if (collect->cascade_fn) 568 - return collect->cascade_fn(var, value, cb); 569 return 0; /* not interested */ 570 } 571 dot = strrchr(key, '.'); ··· 609 strbuf_addstr(&synthkey, collect->section); 610 strbuf_addch(&synthkey, '.'); 611 strbuf_addstr(&synthkey, key); 612 - retval = collect->collect_fn(synthkey.buf, value, collect->cb); 613 614 strbuf_release(&synthkey); 615 return retval;
··· 551 return 0; 552 } 553 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; ··· 566 567 if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') { 568 if (collect->cascade_fn) 569 + return collect->cascade_fn(var, value, ctx, cb); 570 return 0; /* not interested */ 571 } 572 dot = strrchr(key, '.'); ··· 610 strbuf_addstr(&synthkey, collect->section); 611 strbuf_addch(&synthkey, '.'); 612 strbuf_addstr(&synthkey, key); 613 + retval = collect->collect_fn(synthkey.buf, value, ctx, collect->cb); 614 615 strbuf_release(&synthkey); 616 return retval;
+2 -1
urlmatch.h
··· 71 .vars = STRING_LIST_INIT_DUP, \ 72 } 73 74 - int urlmatch_config_entry(const char *var, const char *value, void *cb); 75 void urlmatch_config_release(struct urlmatch_config *config); 76 77 #endif /* URL_MATCH_H */
··· 71 .vars = STRING_LIST_INIT_DUP, \ 72 } 73 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 */
+3 -2
xdiff-interface.c
··· 307 308 int git_xmerge_style = -1; 309 310 - int git_xmerge_config(const char *var, const char *value, void *cb) 311 { 312 if (!strcmp(var, "merge.conflictstyle")) { 313 if (!value) ··· 327 value, var); 328 return 0; 329 } 330 - return git_default_config(var, value, cb); 331 }
··· 307 308 int git_xmerge_style = -1; 309 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) ··· 328 value, var); 329 return 0; 330 } 331 + return git_default_config(var, value, ctx, cb); 332 }
+3 -1
xdiff-interface.h
··· 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); 54 extern int git_xmerge_style; 55 56 /*
··· 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 + 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 /*