219
"from\n"
220
" %s\n"
221
"This might be due to circular includes.");
222
-static int handle_path_include(struct config_source *cs, const char *path,
222
+static int handle_path_include(struct config_source *cs,
223
+ const struct key_value_info *kvi,
224
+ const char *path,
225
struct config_include_data *inc)
226
{
227
int ret = 0;
262
cs->name ? cs->name :
263
"the command line");
264
ret = git_config_from_file_with_options(git_config_include, path, inc,
263
- current_config_scope(),
264
- NULL);
265
+ kvi->scope, NULL);
266
inc->depth--;
267
}
268
cleanup:
511
return ret;
512
513
if (!strcmp(var, "include.path"))
513
- ret = handle_path_include(cs, value, inc);
514
+ ret = handle_path_include(cs, ctx->kvi, value, inc);
515
516
if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
517
cond && include_condition_is_true(cs, inc, cond, cond_len) &&
520
521
if (inc->opts->unconditional_remote_url)
522
inc->fn = forbid_remote_url;
522
- ret = handle_path_include(cs, value, inc);
523
+ ret = handle_path_include(cs, ctx->kvi, value, inc);
524
inc->fn = old_fn;
525
}
526
678
}
679
680
static int config_parse_pair(const char *key, const char *value,
680
- config_fn_t fn, void *data)
681
+ struct key_value_info *kvi,
682
+ config_fn_t fn, void *data)
683
{
684
char *canonical_name;
685
int ret;
686
+ struct config_context ctx = {
687
+ .kvi = kvi,
688
+ };
689
690
if (!strlen(key))
691
return error(_("empty config key"));
692
if (git_config_parse_key(key, &canonical_name, NULL))
693
return -1;
694
690
- ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0;
695
+ ret = (fn(canonical_name, value, &ctx, data) < 0) ? -1 : 0;
696
free(canonical_name);
697
return ret;
698
}
699
700
+
701
+/* for values read from `git_config_from_parameters()` */
702
+void kvi_from_param(struct key_value_info *out)
703
+{
704
+ out->filename = NULL;
705
+ out->linenr = -1;
706
+ out->origin_type = CONFIG_ORIGIN_CMDLINE;
707
+ out->scope = CONFIG_SCOPE_COMMAND;
708
+}
709
+
710
int git_config_parse_parameter(const char *text,
711
config_fn_t fn, void *data)
712
{
713
const char *value;
714
struct strbuf **pair;
715
int ret;
716
+ struct key_value_info kvi = KVI_INIT;
717
+
718
+ kvi_from_param(&kvi);
719
720
pair = strbuf_split_str(text, '=', 2);
721
if (!pair[0])
734
return error(_("bogus config parameter: %s"), text);
735
}
736
719
- ret = config_parse_pair(pair[0]->buf, value, fn, data);
737
+ ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data);
738
strbuf_list_free(pair);
739
return ret;
740
}
741
724
-static int parse_config_env_list(char *env, config_fn_t fn, void *data)
742
+static int parse_config_env_list(char *env, struct key_value_info *kvi,
743
+ config_fn_t fn, void *data)
744
{
745
char *cur = env;
746
while (cur && *cur) {
774
CONFIG_DATA_ENVIRONMENT);
775
}
776
758
- if (config_parse_pair(key, value, fn, data) < 0)
777
+ if (config_parse_pair(key, value, kvi, fn, data) < 0)
778
return -1;
779
}
780
else {
799
int ret = 0;
800
char *envw = NULL;
801
struct config_source source = CONFIG_SOURCE_INIT;
802
+ struct key_value_info kvi = KVI_INIT;
803
804
source.origin_type = CONFIG_ORIGIN_CMDLINE;
805
config_reader_push_source(&the_reader, &source);
806
807
+ kvi_from_param(&kvi);
808
+
809
env = getenv(CONFIG_COUNT_ENVIRONMENT);
810
if (env) {
811
unsigned long count;
841
}
842
strbuf_reset(&envvar);
843
822
- if (config_parse_pair(key, value, fn, data) < 0) {
844
+ if (config_parse_pair(key, value, &kvi, fn, data) < 0) {
845
ret = -1;
846
goto out;
847
}
852
if (env) {
853
/* sq_dequote will write over it */
854
envw = xstrdup(env);
833
- if (parse_config_env_list(envw, fn, data) < 0) {
855
+ if (parse_config_env_list(envw, &kvi, fn, data) < 0) {
856
ret = -1;
857
goto out;
858
}
2464
return 0;
2465
}
2466
2445
-static int configset_add_value(struct config_reader *reader,
2467
+static int configset_add_value(const struct key_value_info *kvi_p,
2468
+ struct config_reader *reader,
2469
struct config_set *set, const char *key,
2470
const char *value)
2471
{
2499
if (!reader->source)
2500
BUG("configset_add_value has no source");
2501
if (reader->source->name) {
2479
- kvi_from_source(reader->source, current_config_scope(), kv_info);
2502
+ kvi_from_source(reader->source, kvi_p->scope, kv_info);
2503
} else {
2481
- /* for values read from `git_config_from_parameters()` */
2482
- kv_info->filename = NULL;
2483
- kv_info->linenr = -1;
2484
- kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
2485
- kv_info->scope = reader->parsing_scope;
2504
+ kvi_from_param(kv_info);
2505
}
2506
si->util = kv_info;
2507
2557
#define CONFIGSET_ADD_INIT { 0 }
2558
2559
static int config_set_callback(const char *key, const char *value,
2541
- const struct config_context *ctx UNUSED,
2560
+ const struct config_context *ctx,
2561
void *cb)
2562
{
2563
struct configset_add_data *data = cb;
2545
- configset_add_value(data->config_reader, data->config_set, key, value);
2564
+ configset_add_value(ctx->kvi, data->config_reader, data->config_set,
2565
+ key, value);
2566
return 0;
2567
}
2568
4057
}
4058
}
4059
4040
-const char *current_config_origin_type(void)
4041
-{
4042
- enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
4043
-
4044
- if (reader_origin_type(&the_reader, &type))
4045
- BUG("current_config_origin_type called outside config callback");
4046
-
4047
- return config_origin_type_name(type);
4048
-}
4049
-
4060
const char *config_scope_name(enum config_scope scope)
4061
{
4062
switch (scope) {
4088
return 0;
4089
}
4090
4081
-const char *current_config_name(void)
4082
-{
4083
- const char *name;
4084
- if (reader_config_name(&the_reader, &name))
4085
- BUG("current_config_name called outside config callback");
4086
- return name ? name : "";
4087
-}
4088
-
4091
enum config_scope current_config_scope(void)
4092
{
4093
if (the_reader.config_kvi)