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>
This commit is contained in:
Glen Choo 2023-06-28 19:26:22 +00:00 committed by Junio C Hamano
parent e0f9a51c32
commit a4e7e317f8
91 changed files with 515 additions and 181 deletions

View File

@ -12,7 +12,8 @@ struct config_alias_data {
struct string_list *list;
};
static int config_alias_cb(const char *key, const char *value, void *d)
static int config_alias_cb(const char *key, const char *value,
const struct config_context *ctx UNUSED, void *d)
{
struct config_alias_data *data = d;
const char *p;

View File

@ -411,7 +411,8 @@ static int tar_filter_config(const char *var, const char *value,
return 0;
}
static int git_tar_config(const char *var, const char *value, void *cb)
static int git_tar_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *cb)
{
if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) {

View File

@ -617,6 +617,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
}
static int archive_zip_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *data UNUSED)
{
return userdiff_config(var, value);

View File

@ -357,7 +357,8 @@ static struct option builtin_add_options[] = {
OPT_END(),
};
static int add_config(const char *var, const char *value, void *cb)
static int add_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "add.ignoreerrors") ||
!strcmp(var, "add.ignore-errors")) {
@ -368,7 +369,7 @@ static int add_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static const char embedded_advice[] = N_(

View File

@ -694,7 +694,8 @@ static const char *add_prefix(const char *prefix, const char *path)
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
}
static int git_blame_config(const char *var, const char *value, void *cb)
static int git_blame_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "blame.showroot")) {
show_root = git_config_bool(var, value);
@ -767,7 +768,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
if (userdiff_config(var, value) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static int blame_copy_callback(const struct option *option, const char *arg, int unset)

View File

@ -83,7 +83,8 @@ static unsigned int colopts;
define_list_config_array(color_branch_slots);
static int git_branch_config(const char *var, const char *value, void *cb)
static int git_branch_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
const char *slot_name;
@ -120,7 +121,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static const char *branch_get_color(enum color_branch ix)

View File

@ -873,12 +873,13 @@ static int batch_objects(struct batch_options *opt)
return retval;
}
static int git_cat_file_config(const char *var, const char *value, void *cb)
static int git_cat_file_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (userdiff_config(var, value) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static int batch_option_callback(const struct option *opt,

View File

@ -1186,7 +1186,8 @@ static int switch_branches(const struct checkout_opts *opts,
return ret || writeout_error;
}
static int git_checkout_config(const char *var, const char *value, void *cb)
static int git_checkout_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
struct checkout_opts *opts = cb;
@ -1202,7 +1203,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
if (starts_with(var, "submodule."))
return git_default_submodule_config(var, value, NULL);
return git_xmerge_config(var, value, NULL);
return git_xmerge_config(var, value, ctx, NULL);
}
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,
}
if (opts->conflict_style) {
struct key_value_info kvi = KVI_INIT;
struct config_context ctx = {
.kvi = &kvi,
};
opts->merge = 1; /* implied */
git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
git_xmerge_config("merge.conflictstyle", opts->conflict_style,
&ctx, NULL);
}
if (opts->force) {
opts->discard_changes = 1;

View File

@ -103,7 +103,8 @@ struct menu_stuff {
define_list_config_array(color_interactive_slots);
static int git_clean_config(const char *var, const char *value, void *cb)
static int git_clean_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
const char *slot_name;
@ -133,7 +134,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static const char *clean_get_color(enum color_clean ix)

View File

@ -790,7 +790,8 @@ static int checkout(int submodule_progress, int filter_submodules)
return err;
}
static int git_clone_config(const char *k, const char *v, void *cb)
static int git_clone_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "clone.defaultremotename")) {
free(remote_name);
@ -801,17 +802,19 @@ static int git_clone_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "clone.filtersubmodules"))
config_filter_submodules = git_config_bool(k, v);
return git_default_config(k, v, cb);
return git_default_config(k, v, ctx, cb);
}
static int write_one_config(const char *key, const char *value, void *data)
static int write_one_config(const char *key, const char *value,
const struct config_context *ctx,
void *data)
{
/*
* give git_clone_config a chance to write config values back to the
* environment, since git_config_set_multivar_gently only deals with
* config-file writes
*/
int apply_failed = git_clone_config(key, value, data);
int apply_failed = git_clone_config(key, value, ctx, data);
if (apply_failed)
return apply_failed;

View File

@ -13,7 +13,8 @@ static const char * const builtin_column_usage[] = {
};
static unsigned int colopts;
static int column_config(const char *var, const char *value, void *cb)
static int column_config(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *cb)
{
return git_column_config(var, value, cb, &colopts);
}

View File

@ -186,6 +186,7 @@ static int write_option_max_new_filters(const struct option *opt,
}
static int git_commit_graph_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, "commitgraph.maxnewfilters"))

View File

@ -1405,7 +1405,8 @@ static int parse_status_slot(const char *slot)
return LOOKUP_CONFIG(color_status_slots, slot);
}
static int git_status_config(const char *k, const char *v, void *cb)
static int git_status_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
const char *slot_name;
@ -1490,7 +1491,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
s->detect_rename = git_config_rename(k, v);
return 0;
}
return git_diff_ui_config(k, v, NULL);
return git_diff_ui_config(k, v, ctx, NULL);
}
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)
return 0;
}
static int git_commit_config(const char *k, const char *v, void *cb)
static int git_commit_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
@ -1627,7 +1629,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
return 0;
}
return git_status_config(k, v, s);
return git_status_config(k, v, ctx, s);
}
int cmd_commit(int argc, const char **argv, const char *prefix)

View File

@ -217,6 +217,7 @@ static void show_config_scope(struct strbuf *buf)
}
static int show_all_config(const char *key_, const char *value_,
const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (show_origin || show_scope) {
@ -301,7 +302,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
return 0;
}
static int collect_config(const char *key_, const char *value_, void *cb)
static int collect_config(const char *key_, const char *value_,
const struct config_context *ctx UNUSED, void *cb)
{
struct strbuf_list *values = cb;
@ -470,6 +472,7 @@ static const char *get_colorbool_slot;
static char parsed_color[COLOR_MAXLEN];
static int git_get_color_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, get_color_slot)) {
@ -503,6 +506,7 @@ static int get_colorbool_found;
static int get_diff_color_found;
static int get_color_ui_found;
static int git_get_colorbool_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *data UNUSED)
{
if (!strcmp(var, get_colorbool_slot))
@ -561,7 +565,9 @@ struct urlmatch_current_candidate_value {
struct strbuf value;
};
static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
static int urlmatch_collect_fn(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb)
{
struct string_list *values = cb;
struct string_list_item *item = string_list_insert(values, var);

View File

@ -40,14 +40,15 @@ static const char *const builtin_difftool_usage[] = {
NULL
};
static int difftool_config(const char *var, const char *value, void *cb)
static int difftool_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "difftool.trustexitcode")) {
trust_exit_code = git_config_bool(var, value);
return 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static int print_tool_help(void)

View File

@ -110,7 +110,8 @@ struct fetch_config {
int submodule_fetch_jobs;
};
static int git_fetch_config(const char *k, const char *v, void *cb)
static int git_fetch_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
struct fetch_config *fetch_config = cb;
@ -164,7 +165,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
"fetch.output", v);
}
return git_default_config(k, v, cb);
return git_default_config(k, v, ctx, cb);
}
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@ -1799,7 +1800,9 @@ struct remote_group_data {
struct string_list *list;
};
static int get_remote_group(const char *key, const char *value, void *priv)
static int get_remote_group(const char *key, const char *value,
const struct config_context *ctx UNUSED,
void *priv)
{
struct remote_group_data *g = priv;

View File

@ -37,7 +37,8 @@ static int fsmonitor__start_timeout_sec = 60;
#define FSMONITOR__ANNOUNCE_STARTUP "fsmonitor.announcestartup"
static int fsmonitor__announce_startup = 0;
static int fsmonitor_config(const char *var, const char *value, void *cb)
static int fsmonitor_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
int i = git_config_int(var, value);
@ -67,7 +68,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
return 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
/*

View File

@ -290,13 +290,14 @@ static int wait_all(void)
return hit;
}
static int grep_cmd_config(const char *var, const char *value, void *cb)
static int grep_cmd_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
int st = grep_config(var, value, cb);
int st = grep_config(var, value, ctx, cb);
if (git_color_config(var, value, cb) < 0)
st = -1;
else if (git_default_config(var, value, cb) < 0)
else if (git_default_config(var, value, ctx, cb) < 0)
st = -1;
if (!strcmp(var, "grep.threads")) {

View File

@ -398,7 +398,8 @@ static int add_man_viewer_info(const char *var, const char *value)
return 0;
}
static int git_help_config(const char *var, const char *value, void *cb)
static int git_help_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "help.format")) {
if (!value)
@ -421,7 +422,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
if (starts_with(var, "man."))
return add_man_viewer_info(var, value);
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static struct cmdnames main_cmds, other_cmds;

View File

@ -1581,7 +1581,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
strbuf_release(&pack_name);
}
static int git_index_pack_config(const char *k, const char *v, void *cb)
static int git_index_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
struct pack_idx_option *opts = cb;
@ -1608,7 +1609,7 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
else
opts->flags &= ~WRITE_REV;
}
return git_default_config(k, v, cb);
return git_default_config(k, v, ctx, cb);
}
static int cmp_uint32(const void *a_, const void *b_)

View File

@ -564,7 +564,8 @@ static int cmd_log_walk(struct rev_info *rev)
return retval;
}
static int git_log_config(const char *var, const char *value, void *cb)
static int git_log_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
const char *slot_name;
@ -613,7 +614,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
return 0;
}
return git_diff_ui_config(var, value, cb);
return git_diff_ui_config(var, value, ctx, cb);
}
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)
die(_("%s: invalid cover from description mode"), arg);
}
static int git_format_config(const char *var, const char *value, void *cb)
static int git_format_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "format.headers")) {
if (!value)
@ -1108,7 +1110,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "diff.noprefix"))
return 0;
return git_log_config(var, value, cb);
return git_log_config(var, value, ctx, cb);
}
static const char *output_directory = NULL;

View File

@ -623,7 +623,8 @@ static void parse_branch_merge_options(char *bmo)
free(argv);
}
static int git_merge_config(const char *k, const char *v, void *cb)
static int git_merge_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
int status;
const char *str;
@ -668,10 +669,10 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return 0;
}
status = fmt_merge_msg_config(k, v, cb);
status = fmt_merge_msg_config(k, v, ctx, cb);
if (status)
return status;
return git_diff_ui_config(k, v, cb);
return git_diff_ui_config(k, v, ctx, cb);
}
static int read_tree_trivial(struct object_id *common, struct object_id *head,

View File

@ -82,6 +82,7 @@ static struct option *add_common_options(struct option *prev)
}
static int git_multi_pack_index_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, "pack.writebitmaphashcache")) {

View File

@ -3135,7 +3135,8 @@ static void prepare_pack(int window, int depth)
free(delta_list);
}
static int git_pack_config(const char *k, const char *v, void *cb)
static int git_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "pack.window")) {
window = git_config_int(k, v);
@ -3227,7 +3228,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
ex->uri = xstrdup(pack_end + 1);
oidmap_put(&configured_exclusions, ex);
}
return git_default_config(k, v, cb);
return git_default_config(k, v, ctx, cb);
}
/* Counters for trace2 output when in --stdin-packs mode. */

View File

@ -196,7 +196,8 @@ struct patch_id_opts {
int verbatim;
};
static int git_patch_id_config(const char *var, const char *value, void *cb)
static int git_patch_id_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
struct patch_id_opts *opts = cb;
@ -209,7 +210,7 @@ static int git_patch_id_config(const char *var, const char *value, void *cb)
return 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
int cmd_patch_id(int argc, const char **argv, const char *prefix)

View File

@ -361,7 +361,8 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified)
/**
* Read config variables.
*/
static int git_pull_config(const char *var, const char *value, void *cb)
static int git_pull_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "rebase.autostash")) {
config_autostash = git_config_bool(var, value);
@ -374,7 +375,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
check_trust_level = 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
/**

View File

@ -510,7 +510,8 @@ static void set_push_cert_flags(int *flags, int v)
}
static int git_push_config(const char *k, const char *v, void *cb)
static int git_push_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
const char *slot_name;
int *flags = cb;
@ -577,7 +578,7 @@ static int git_push_config(const char *k, const char *v, void *cb)
return 0;
}
return git_default_config(k, v, NULL);
return git_default_config(k, v, ctx, NULL);
}
int cmd_push(int argc, const char **argv, const char *prefix)

View File

@ -102,12 +102,13 @@ static int debug_merge(const struct cache_entry * const *stages,
return 0;
}
static int git_read_tree_config(const char *var, const char *value, void *cb)
static int git_read_tree_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)

View File

@ -772,7 +772,8 @@ static void parse_rebase_merges_value(struct rebase_options *options, const char
die(_("Unknown rebase-merges mode: %s"), value);
}
static int rebase_config(const char *var, const char *value, void *data)
static int rebase_config(const char *var, const char *value,
const struct config_context *ctx, void *data)
{
struct rebase_options *opts = data;
@ -831,7 +832,7 @@ static int rebase_config(const char *var, const char *value, void *data)
return git_config_string(&opts->default_backend, var, value);
}
return git_default_config(var, value, data);
return git_default_config(var, value, ctx, data);
}
static int checkout_up_to_date(struct rebase_options *options)

View File

@ -139,7 +139,8 @@ static enum deny_action parse_deny_action(const char *var, const char *value)
return DENY_IGNORE;
}
static int receive_pack_config(const char *var, const char *value, void *cb)
static int receive_pack_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
int status = parse_hide_refs_config(var, value, "receive", &hidden_refs);
@ -266,7 +267,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static void show_ref(const char *path, const struct object_id *oid)

View File

@ -108,7 +108,8 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
#define EXPIRE_TOTAL 01
#define EXPIRE_UNREACH 02
static int reflog_expire_config(const char *var, const char *value, void *cb)
static int reflog_expire_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
const char *pattern, *key;
size_t pattern_len;
@ -117,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
struct reflog_expire_cfg *ent;
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
if (!strcmp(key, "reflogexpire")) {
slot = EXPIRE_TOTAL;
@ -128,7 +129,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
if (git_config_expiry_date(&expire, var, value))
return -1;
} else
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
if (!pattern) {
switch (slot) {

View File

@ -268,6 +268,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
#define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
static int config_read_branches(const char *key, const char *value,
const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *orig_key = key;
@ -645,7 +646,7 @@ struct push_default_info
};
static int config_read_push_default(const char *key, const char *value,
void *cb)
const struct config_context *ctx UNUSED, void *cb)
{
struct push_default_info* info = cb;
if (strcmp(key, "remote.pushdefault") ||
@ -1494,7 +1495,9 @@ static int prune(int argc, const char **argv, const char *prefix)
return result;
}
static int get_remote_default(const char *key, const char *value UNUSED, void *priv)
static int get_remote_default(const char *key, const char *value UNUSED,
const struct config_context *ctx UNUSED,
void *priv)
{
if (strcmp(key, "remotes.default") == 0) {
int *found = priv;

View File

@ -59,7 +59,8 @@ struct pack_objects_args {
int local;
};
static int repack_config(const char *var, const char *value, void *cb)
static int repack_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
struct pack_objects_args *cruft_po_args = cb;
if (!strcmp(var, "repack.usedeltabaseoffset")) {
@ -91,7 +92,7 @@ static int repack_config(const char *var, const char *value, void *cb)
return git_config_string(&cruft_po_args->depth, var, value);
if (!strcmp(var, "repack.cruftthreads"))
return git_config_string(&cruft_po_args->threads, var, value);
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
/*

View File

@ -312,12 +312,13 @@ static int reset_refs(const char *rev, const struct object_id *oid)
return update_ref_status;
}
static int git_reset_config(const char *var, const char *value, void *cb)
static int git_reset_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
int cmd_reset(int argc, const char **argv, const char *prefix)

View File

@ -131,7 +131,8 @@ static void print_helper_status(struct ref *ref)
strbuf_release(&buf);
}
static int send_pack_config(const char *k, const char *v, void *cb)
static int send_pack_config(const char *k, const char *v,
const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "push.gpgsign")) {
const char *value;
@ -151,7 +152,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
}
}
}
return git_default_config(k, v, cb);
return git_default_config(k, v, ctx, cb);
}
int cmd_send_pack(int argc, const char **argv, const char *prefix)

View File

@ -559,7 +559,8 @@ static void append_one_rev(const char *av)
die("bad sha1 reference %s", av);
}
static int git_show_branch_config(const char *var, const char *value, void *cb)
static int git_show_branch_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "showbranch.default")) {
if (!value)
@ -582,7 +583,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)

View File

@ -837,7 +837,8 @@ static int show_stat = 1;
static int show_patch;
static int show_include_untracked;
static int git_stash_config(const char *var, const char *value, void *cb)
static int git_stash_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "stash.showstat")) {
show_stat = git_config_bool(var, value);
@ -851,7 +852,7 @@ static int git_stash_config(const char *var, const char *value, void *cb)
show_include_untracked = git_config_bool(var, value);
return 0;
}
return git_diff_basic_config(var, value, cb);
return git_diff_basic_config(var, value, ctx, cb);
}
static void diff_include_untracked(const struct stash_info *info, struct diff_options *diff_opt)

View File

@ -2192,6 +2192,7 @@ static int update_clone_task_finished(int result,
}
static int git_update_clone_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb)
{
int *max_jobs = cb;

View File

@ -188,7 +188,8 @@ static const char tag_template_nocleanup[] =
"Lines starting with '%c' will be kept; you may remove them"
" yourself if you want to.\n");
static int git_tag_config(const char *var, const char *value, void *cb)
static int git_tag_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "tag.gpgsign")) {
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)
if (git_color_config(var, value, cb) < 0)
return -1;
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static void write_tag_body(int fd, const struct object_id *oid)

View File

@ -71,13 +71,14 @@ static const struct git_var *get_git_var(const char *var)
return NULL;
}
static int show_config(const char *var, const char *value, void *cb)
static int show_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (value)
printf("%s=%s\n", var, value);
else
printf("%s\n", var);
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
int cmd_var(int argc, const char **argv, const char *prefix UNUSED)

View File

@ -128,14 +128,15 @@ static int verbose;
static int guess_remote;
static timestamp_t expire;
static int git_worktree_config(const char *var, const char *value, void *cb)
static int git_worktree_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "worktree.guessremote")) {
guess_remote = git_config_bool(var, value);
return 0;
}
return git_default_config(var, value, cb);
return git_default_config(var, value, ctx, cb);
}
static int delete_git_dir(const char *id)

View File

@ -224,7 +224,9 @@ static int bundle_list_update(const char *key, const char *value,
return 0;
}
static int config_to_bundle_list(const char *key, const char *value, void *data)
static int config_to_bundle_list(const char *key, const char *value,
const struct config_context *ctx UNUSED,
void *data)
{
struct bundle_list *list = data;
return bundle_list_update(key, value, list);
@ -871,7 +873,9 @@ cached:
return advertise_bundle_uri;
}
static int config_to_packet_line(const char *key, const char *value, void *data)
static int config_to_packet_line(const char *key, const char *value,
const struct config_context *ctx UNUSED,
void *data)
{
struct packet_reader *writer = data;

View File

@ -244,7 +244,8 @@ static int core_restrict_inherited_handles = -1;
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
static char *unset_environment_variables;
int mingw_core_config(const char *var, const char *value, void *cb)
int mingw_core_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.hidedotfiles")) {
if (value && !strcasecmp(value, "dotgitonly"))

View File

@ -11,7 +11,9 @@ typedef _sigset_t sigset_t;
#undef _POSIX_THREAD_SAFE_FUNCTIONS
#endif
int mingw_core_config(const char *var, const char *value, void *cb);
struct config_context;
int mingw_core_config(const char *var, const char *value,
const struct config_context *ctx, void *cb);
#define platform_core_config mingw_core_config
/*

View File

@ -209,7 +209,8 @@ struct config_include_data {
};
#define CONFIG_INCLUDE_INIT { 0 }
static int git_config_include(const char *var, const char *value, void *data);
static int git_config_include(const char *var, const char *value,
const struct config_context *ctx, void *data);
#define MAX_INCLUDE_DEPTH 10
static const char include_depth_advice[] = N_(
@ -388,7 +389,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
return ret;
}
static int add_remote_url(const char *var, const char *value, void *data)
static int add_remote_url(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *data)
{
struct string_list *remote_urls = data;
const char *remote_name;
@ -423,6 +425,7 @@ static void populate_remote_urls(struct config_include_data *inc)
}
static int forbid_remote_url(const char *var, const char *value UNUSED,
const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *remote_name;
@ -486,7 +489,9 @@ static int include_condition_is_true(struct config_source *cs,
return 0;
}
static int git_config_include(const char *var, const char *value, void *data)
static int git_config_include(const char *var, const char *value,
const struct config_context *ctx,
void *data)
{
struct config_include_data *inc = data;
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)
* Pass along all values, including "include" directives; this makes it
* possible to query information on the includes themselves.
*/
ret = inc->fn(var, value, inc->data);
ret = inc->fn(var, value, NULL, inc->data);
if (ret < 0)
return ret;
@ -680,7 +685,7 @@ static int config_parse_pair(const char *key, const char *value,
if (git_config_parse_key(key, &canonical_name, NULL))
return -1;
ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0;
free(canonical_name);
return ret;
}
@ -968,7 +973,7 @@ static int get_value(struct config_source *cs, config_fn_t fn, void *data,
* accurate line number in error messages.
*/
cs->linenr--;
ret = fn(name->buf, value, data);
ret = fn(name->buf, value, NULL, data);
if (ret >= 0)
cs->linenr++;
return ret;
@ -1562,7 +1567,8 @@ int git_config_color(char *dest, const char *var, const char *value)
return 0;
}
static int git_default_core_config(const char *var, const char *value, void *cb)
static int git_default_core_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
/* This needs a better name */
if (!strcmp(var, "core.filemode")) {
@ -1842,7 +1848,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
}
/* Add other config variables here and to Documentation/config.txt. */
return platform_core_config(var, value, cb);
return platform_core_config(var, value, ctx, cb);
}
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)
return 0;
}
int git_default_config(const char *var, const char *value, void *cb)
int git_default_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
if (starts_with(var, "core."))
return git_default_core_config(var, value, cb);
return git_default_core_config(var, value, ctx, cb);
if (starts_with(var, "user.") ||
starts_with(var, "author.") ||
starts_with(var, "committer."))
return git_ident_config(var, value, cb);
return git_ident_config(var, value, ctx, cb);
if (starts_with(var, "i18n."))
return git_default_i18n_config(var, value);
@ -2318,7 +2325,7 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
config_reader_set_kvi(reader, values->items[value_index].util);
if (fn(entry->key, values->items[value_index].string, data) < 0)
if (fn(entry->key