Skip to content

Commit

Permalink
Merge branch 'gc/config-context'
Browse files Browse the repository at this point in the history
Reduce reliance on a global state in the config reading API.

* gc/config-context:
  config: pass source to config_parser_event_fn_t
  config: add kvi.path, use it to evaluate includes
  config.c: remove config_reader from configsets
  config: pass kvi to die_bad_number()
  trace2: plumb config kvi
  config.c: pass ctx with CLI config
  config: pass ctx with config files
  config.c: pass ctx in configsets
  config: add ctx arg to config_fn_t
  urlmatch.h: use config_fn_t type
  config: inline git_color_default_config
  • Loading branch information
gitster committed Jul 6, 2023
2 parents 1d76e69 + 6e8e798 commit b3d1c85
Show file tree
Hide file tree
Showing 103 changed files with 960 additions and 632 deletions.
3 changes: 2 additions & 1 deletion alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,15 @@ 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, void *cb)
{
if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) {
tar_umask = umask(0);
umask(tar_umask);
} else {
tar_umask = git_config_int(var, value);
tar_umask = git_config_int(var, value, ctx->kvi);
}
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions archive-zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,19 @@ 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")) {
ignore_add_errors = git_config_bool(var, value);
return 0;
}

return git_color_default_config(var, value, cb);
if (git_color_config(var, value, cb) < 0)
return -1;

return git_default_config(var, value, ctx, cb);
}

static const char embedded_advice[] = N_(
Expand Down
5 changes: 3 additions & 2 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -117,7 +118,10 @@ static int git_branch_config(const char *var, const char *value, void *cb)
return 0;
}

return git_color_default_config(var, value, cb);
if (git_color_config(var, value, cb) < 0)
return -1;

return git_default_config(var, value, ctx, cb);
}

static const char *branch_get_color(enum color_branch ix)
Expand Down
5 changes: 3 additions & 2 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,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,
Expand Down
12 changes: 9 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,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;

Expand All @@ -1205,7 +1206,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(
Expand Down Expand Up @@ -1692,8 +1693,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;
Expand Down
9 changes: 6 additions & 3 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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;

Expand All @@ -131,8 +132,10 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
}

/* inspect the color.ui config variable and others */
return git_color_default_config(var, value, cb);
if (git_color_config(var, value, cb) < 0)
return -1;

return git_default_config(var, value, ctx, cb);
}

static const char *clean_get_color(enum color_clean ix)
Expand Down
11 changes: 7 additions & 4 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,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);
Expand All @@ -802,17 +803,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;

Expand Down
3 changes: 2 additions & 1 deletion builtin/column.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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);
}
Expand Down
3 changes: 2 additions & 1 deletion builtin/commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ 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,
void *cb UNUSED)
{
if (!strcmp(var, "commitgraph.maxnewfilters"))
write_opts.max_new_filters = git_config_int(var, value);
write_opts.max_new_filters = git_config_int(var, value, ctx->kvi);
/*
* No need to fall-back to 'git_default_config', since this was already
* called in 'cmd_commit_graph()'.
Expand Down
20 changes: 12 additions & 8 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,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;
Expand All @@ -1419,7 +1420,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
return git_column_config(k, v, "status", &s->colopts);
if (!strcmp(k, "status.submodulesummary")) {
int is_bool;
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
s->submodule_summary = git_config_bool_or_int(k, v, ctx->kvi,
&is_bool);
if (is_bool && s->submodule_summary)
s->submodule_summary = -1;
return 0;
Expand Down Expand Up @@ -1479,11 +1481,11 @@ static int git_status_config(const char *k, const char *v, void *cb)
}
if (!strcmp(k, "diff.renamelimit")) {
if (s->rename_limit == -1)
s->rename_limit = git_config_int(k, v);
s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "status.renamelimit")) {
s->rename_limit = git_config_int(k, v);
s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "diff.renames")) {
Expand All @@ -1495,7 +1497,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)
Expand Down Expand Up @@ -1610,7 +1612,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;

Expand All @@ -1628,11 +1631,12 @@ static int git_commit_config(const char *k, const char *v, void *cb)
}
if (!strcmp(k, "commit.verbose")) {
int is_bool;
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
config_commit_verbose = git_config_bool_or_int(k, v, ctx->kvi,
&is_bool);
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)
Expand Down
Loading

0 comments on commit b3d1c85

Please sign in to comment.