config.c: remove config_reader from configsets

Remove the last usage of "struct config_reader" from configsets by
copying the "kvi" arg instead of recomputing "kvi" from
config_reader.source. Since we no longer need to pass both "struct
config_reader" and "struct config_set" in a single "void *cb", remove
"struct configset_add_data" too.

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Glen Choo 2023-06-28 19:26:28 +00:00 committed by Junio C Hamano
parent 8868b1ebfb
commit f6c213a0cb
1 changed files with 11 additions and 34 deletions

View File

@ -2311,8 +2311,7 @@ int config_with_options(config_fn_t fn, void *data,
return ret; return ret;
} }


static void configset_iter(struct config_reader *reader, struct config_set *set, static void configset_iter(struct config_set *set, config_fn_t fn, void *data)
config_fn_t fn, void *data)
{ {
int i, value_index; int i, value_index;
struct string_list *values; struct string_list *values;
@ -2406,7 +2405,6 @@ static int configset_find_element(struct config_set *set, const char *key,
} }


static int configset_add_value(const struct key_value_info *kvi_p, static int configset_add_value(const struct key_value_info *kvi_p,
struct config_reader *reader,
struct config_set *set, const char *key, struct config_set *set, const char *key,
const char *value) const char *value)
{ {
@ -2437,13 +2435,7 @@ static int configset_add_value(const struct key_value_info *kvi_p,
l_item->e = e; l_item->e = e;
l_item->value_index = e->value_list.nr - 1; l_item->value_index = e->value_list.nr - 1;


if (!reader->source) *kv_info = *kvi_p;
BUG("configset_add_value has no source");
if (reader->source->name) {
kvi_from_source(reader->source, kvi_p->scope, kv_info);
} else {
kvi_from_param(kv_info);
}
si->util = kv_info; si->util = kv_info;


return 0; return 0;
@ -2491,28 +2483,18 @@ void git_configset_clear(struct config_set *set)
set->list.items = NULL; set->list.items = NULL;
} }


struct configset_add_data {
struct config_set *config_set;
struct config_reader *config_reader;
};
#define CONFIGSET_ADD_INIT { 0 }

static int config_set_callback(const char *key, const char *value, static int config_set_callback(const char *key, const char *value,
const struct config_context *ctx, const struct config_context *ctx,
void *cb) void *cb)
{ {
struct configset_add_data *data = cb; struct config_set *set = cb;
configset_add_value(ctx->kvi, data->config_reader, data->config_set, configset_add_value(ctx->kvi, set, key, value);
key, value);
return 0; return 0;
} }


int git_configset_add_file(struct config_set *set, const char *filename) int git_configset_add_file(struct config_set *set, const char *filename)
{ {
struct configset_add_data data = CONFIGSET_ADD_INIT; return git_config_from_file(config_set_callback, filename, set);
data.config_reader = &the_reader;
data.config_set = set;
return git_config_from_file(config_set_callback, filename, &data);
} }


int git_configset_get_value(struct config_set *set, const char *key, int git_configset_get_value(struct config_set *set, const char *key,
@ -2678,7 +2660,6 @@ int git_configset_get_pathname(struct config_set *set, const char *key, const ch
static void repo_read_config(struct repository *repo) static void repo_read_config(struct repository *repo)
{ {
struct config_options opts = { 0 }; struct config_options opts = { 0 };
struct configset_add_data data = CONFIGSET_ADD_INIT;


opts.respect_includes = 1; opts.respect_includes = 1;
opts.commondir = repo->commondir; opts.commondir = repo->commondir;
@ -2690,10 +2671,8 @@ static void repo_read_config(struct repository *repo)
git_configset_clear(repo->config); git_configset_clear(repo->config);


git_configset_init(repo->config); git_configset_init(repo->config);
data.config_set = repo->config; if (config_with_options(config_set_callback, repo->config, NULL,
data.config_reader = &the_reader; repo, &opts) < 0)

if (config_with_options(config_set_callback, &data, NULL, repo, &opts) < 0)
/* /*
* config_with_options() normally returns only * config_with_options() normally returns only
* zero, as most errors are fatal, and * zero, as most errors are fatal, and
@ -2725,7 +2704,7 @@ static void repo_config_clear(struct repository *repo)
void repo_config(struct repository *repo, config_fn_t fn, void *data) void repo_config(struct repository *repo, config_fn_t fn, void *data)
{ {
git_config_check_init(repo); git_config_check_init(repo);
configset_iter(&the_reader, repo->config, fn, data); configset_iter(repo->config, fn, data);
} }


int repo_config_get(struct repository *repo, const char *key) int repo_config_get(struct repository *repo, const char *key)
@ -2832,19 +2811,17 @@ static void read_protected_config(void)
.ignore_worktree = 1, .ignore_worktree = 1,
.system_gently = 1, .system_gently = 1,
}; };
struct configset_add_data data = CONFIGSET_ADD_INIT;


git_configset_init(&protected_config); git_configset_init(&protected_config);
data.config_set = &protected_config; config_with_options(config_set_callback, &protected_config, NULL,
data.config_reader = &the_reader; NULL, &opts);
config_with_options(config_set_callback, &data, NULL, NULL, &opts);
} }


void git_protected_config(config_fn_t fn, void *data) void git_protected_config(config_fn_t fn, void *data)
{ {
if (!protected_config.hash_initialized) if (!protected_config.hash_initialized)
read_protected_config(); read_protected_config();
configset_iter(&the_reader, &protected_config, fn, data); configset_iter(&protected_config, fn, data);
} }


/* Functions used historically to read configuration from 'the_repository' */ /* Functions used historically to read configuration from 'the_repository' */