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>
Glen Choo committed
Jun 28, 2023 at 19:26 UTC
f6c213a0cbf7071c845eef0afa4bc5f9c4883e51
1 file changed
+11
-34
config.c
+11
-34
@@ -2311,8 +2311,7 @@ int config_with_options(config_fn_t fn, void *data,
2311
return ret;
2312
}
2313
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)
2315
{
2316
int i, value_index;
2317
struct string_list *values;
@@ -2406,7 +2405,6 @@ static int configset_find_element(struct config_set *set, const char *key,
2405
}
2406
2407
static int configset_add_value(const struct key_value_info *kvi_p,
2409
- struct config_reader *reader,
2408
struct config_set *set, const char *key,
2409
const char *value)
2410
{
@@ -2437,13 +2435,7 @@ static int configset_add_value(const struct key_value_info *kvi_p,
2435
l_item->e = e;
2436
l_item->value_index = e->value_list.nr - 1;
2437
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;
2439
si->util = kv_info;
2440
2441
return 0;
@@ -2491,28 +2483,18 @@ void git_configset_clear(struct config_set *set)
2483
set->list.items = NULL;
2484
}
2485
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
-
2486
static int config_set_callback(const char *key, const char *value,
2487
const struct config_context *ctx,
2488
void *cb)
2489
{
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);
2492
return 0;
2493
}
2494
2495
int git_configset_add_file(struct config_set *set, const char *filename)
2496
{
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);
2498
}
2499
2500
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
2660
static void repo_read_config(struct repository *repo)
2661
{
2662
struct config_options opts = { 0 };
2681
- struct configset_add_data data = CONFIGSET_ADD_INIT;
2663
2664
opts.respect_includes = 1;
2665
opts.commondir = repo->commondir;
@@ -2690,10 +2671,8 @@ static void repo_read_config(struct repository *repo)
2671
git_configset_clear(repo->config);
2672
2673
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)
2676
/*
2677
* config_with_options() normally returns only
2678
* zero, as most errors are fatal, and
@@ -2725,7 +2704,7 @@ static void repo_config_clear(struct repository *repo)
2704
void repo_config(struct repository *repo, config_fn_t fn, void *data)
2705
{
2706
git_config_check_init(repo);
2728
- configset_iter(&the_reader, repo->config, fn, data);
2707
+ configset_iter(repo->config, fn, data);
2708
}
2709
2710
int repo_config_get(struct repository *repo, const char *key)
@@ -2832,19 +2811,17 @@ static void read_protected_config(void)
2811
.ignore_worktree = 1,
2812
.system_gently = 1,
2813
};
2835
- struct configset_add_data data = CONFIGSET_ADD_INIT;
2814
2815
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);
2818
}
2819
2820
void git_protected_config(config_fn_t fn, void *data)
2821
{
2822
if (!protected_config.hash_initialized)
2823
read_protected_config();
2847
- configset_iter(&the_reader, &protected_config, fn, data);
2824
+ configset_iter(&protected_config, fn, data);
2825
}
2826
2827
/* Functions used historically to read configuration from 'the_repository' */