85
*/
86
struct config_source *source;
87
struct key_value_info *config_kvi;
88
- /*
89
- * The "scope" of the current config source being parsed (repo, global,
90
- * etc). Like "source", this is only set when parsing a config source.
91
- * It's not part of "source" because it transcends a single file (i.e.,
92
- * a file included from .git/config is still in "repo" scope).
93
- *
94
- * When iterating through a configset, the equivalent value is
95
- * "config_kvi.scope" (see above).
96
- */
97
- enum config_scope parsing_scope;
88
};
89
/*
90
* Where possible, prefer to accept "struct config_reader" as an arg than to use
115
static inline void config_reader_set_kvi(struct config_reader *reader,
116
struct key_value_info *kvi)
117
{
128
- if (kvi && (reader->source || reader->parsing_scope))
129
- BUG("kvi should not be set while parsing a config source");
118
reader->config_kvi = kvi;
119
}
120
133
-static inline void config_reader_set_scope(struct config_reader *reader,
134
- enum config_scope scope)
135
-{
136
- if (scope && reader->config_kvi)
137
- BUG("scope should only be set when iterating through a config source");
138
- reader->parsing_scope = scope;
139
-}
140
-
121
static int pack_compression_seen;
122
static int zlib_compression_seen;
123
392
{
393
struct config_options opts;
394
415
- enum config_scope store_scope = inc->config_reader->parsing_scope;
416
-
395
opts = *inc->opts;
396
opts.unconditional_remote_url = 1;
397
420
- config_reader_set_scope(inc->config_reader, 0);
421
-
398
inc->remote_urls = xmalloc(sizeof(*inc->remote_urls));
399
string_list_init_dup(inc->remote_urls);
400
config_with_options(add_remote_url, inc->remote_urls,
401
inc->config_source, inc->repo, &opts);
426
-
427
- config_reader_set_scope(inc->config_reader, store_scope);
402
}
403
404
static int forbid_remote_url(const char *var, const char *value UNUSED,
2229
char *user_config = NULL;
2230
char *repo_config;
2231
char *worktree_config;
2258
- enum config_scope prev_parsing_scope = reader->parsing_scope;
2232
2233
/*
2234
* Ensure that either:
2246
worktree_config = NULL;
2247
}
2248
2276
- config_reader_set_scope(reader, CONFIG_SCOPE_SYSTEM);
2249
if (git_config_system() && system_config &&
2250
!access_or_die(system_config, R_OK,
2251
opts->system_gently ? ACCESS_EACCES_OK : 0))
2253
data, CONFIG_SCOPE_SYSTEM,
2254
NULL);
2255
2284
- config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL);
2256
git_global_config(&user_config, &xdg_config);
2257
2258
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
2263
ret += git_config_from_file_with_options(fn, user_config, data,
2264
CONFIG_SCOPE_GLOBAL, NULL);
2265
2295
- config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL);
2266
if (!opts->ignore_repo && repo_config &&
2267
!access_or_die(repo_config, R_OK, 0))
2268
ret += git_config_from_file_with_options(fn, repo_config, data,
2269
CONFIG_SCOPE_LOCAL, NULL);
2270
2301
- config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE);
2271
if (!opts->ignore_worktree && worktree_config &&
2272
repo && repo->repository_format_worktree_config &&
2273
!access_or_die(worktree_config, R_OK, 0)) {
2276
NULL);
2277
}
2278
2310
- config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND);
2279
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
2280
die(_("unable to parse command-line config"));
2281
2314
- config_reader_set_scope(reader, prev_parsing_scope);
2282
free(system_config);
2283
free(xdg_config);
2284
free(user_config);
2293
const struct config_options *opts)
2294
{
2295
struct config_include_data inc = CONFIG_INCLUDE_INIT;
2329
- enum config_scope prev_scope = the_reader.parsing_scope;
2296
int ret;
2297
2298
if (opts->respect_includes) {
2306
data = &inc;
2307
}
2308
2343
- if (config_source)
2344
- config_reader_set_scope(&the_reader, config_source->scope);
2345
-
2309
/*
2310
* If we have a specific filename, use it. Otherwise, follow the
2311
* regular lookup sequence.
2327
string_list_clear(inc.remote_urls, 0);
2328
FREE_AND_NULL(inc.remote_urls);
2329
}
2367
- config_reader_set_scope(&the_reader, prev_scope);
2330
return ret;
2331
}
2332
4050
return 0;
4051
}
4052
4091
-enum config_scope current_config_scope(void)
4092
-{
4093
- if (the_reader.config_kvi)
4094
- return the_reader.config_kvi->scope;
4095
- else
4096
- return the_reader.parsing_scope;
4097
-}
4098
-
4053
int lookup_config(const char **mapping, int nr_mapping, const char *var)
4054
{
4055
int i;