Skip to content

Commit f6c213a

Browse files
chooglengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8868b1e commit f6c213a

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

config.c

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,8 +2311,7 @@ int config_with_options(config_fn_t fn, void *data,
23112311
return ret;
23122312
}
23132313

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

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

2440-
if (!reader->source)
2441-
BUG("configset_add_value has no source");
2442-
if (reader->source->name) {
2443-
kvi_from_source(reader->source, kvi_p->scope, kv_info);
2444-
} else {
2445-
kvi_from_param(kv_info);
2446-
}
2438+
*kv_info = *kvi_p;
24472439
si->util = kv_info;
24482440

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

2494-
struct configset_add_data {
2495-
struct config_set *config_set;
2496-
struct config_reader *config_reader;
2497-
};
2498-
#define CONFIGSET_ADD_INIT { 0 }
2499-
25002486
static int config_set_callback(const char *key, const char *value,
25012487
const struct config_context *ctx,
25022488
void *cb)
25032489
{
2504-
struct configset_add_data *data = cb;
2505-
configset_add_value(ctx->kvi, data->config_reader, data->config_set,
2506-
key, value);
2490+
struct config_set *set = cb;
2491+
configset_add_value(ctx->kvi, set, key, value);
25072492
return 0;
25082493
}
25092494

25102495
int git_configset_add_file(struct config_set *set, const char *filename)
25112496
{
2512-
struct configset_add_data data = CONFIGSET_ADD_INIT;
2513-
data.config_reader = &the_reader;
2514-
data.config_set = set;
2515-
return git_config_from_file(config_set_callback, filename, &data);
2497+
return git_config_from_file(config_set_callback, filename, set);
25162498
}
25172499

25182500
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
26782660
static void repo_read_config(struct repository *repo)
26792661
{
26802662
struct config_options opts = { 0 };
2681-
struct configset_add_data data = CONFIGSET_ADD_INIT;
26822663

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

26922673
git_configset_init(repo->config);
2693-
data.config_set = repo->config;
2694-
data.config_reader = &the_reader;
2695-
2696-
if (config_with_options(config_set_callback, &data, NULL, repo, &opts) < 0)
2674+
if (config_with_options(config_set_callback, repo->config, NULL,
2675+
repo, &opts) < 0)
26972676
/*
26982677
* config_with_options() normally returns only
26992678
* zero, as most errors are fatal, and
@@ -2725,7 +2704,7 @@ static void repo_config_clear(struct repository *repo)
27252704
void repo_config(struct repository *repo, config_fn_t fn, void *data)
27262705
{
27272706
git_config_check_init(repo);
2728-
configset_iter(&the_reader, repo->config, fn, data);
2707+
configset_iter(repo->config, fn, data);
27292708
}
27302709

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

28372815
git_configset_init(&protected_config);
2838-
data.config_set = &protected_config;
2839-
data.config_reader = &the_reader;
2840-
config_with_options(config_set_callback, &data, NULL, NULL, &opts);
2816+
config_with_options(config_set_callback, &protected_config, NULL,
2817+
NULL, &opts);
28412818
}
28422819

28432820
void git_protected_config(config_fn_t fn, void *data)
28442821
{
28452822
if (!protected_config.hash_initialized)
28462823
read_protected_config();
2847-
configset_iter(&the_reader, &protected_config, fn, data);
2824+
configset_iter(&protected_config, fn, data);
28482825
}
28492826

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

0 commit comments

Comments
 (0)