Skip to content

Commit e895589

Browse files
committed
git-config: use git_config_with_options
The git-config command has always implemented its own file lookup and parsing order. This was necessary because its duplicate-entry handling did not match the way git's internal callbacks worked. Now that this is no longer the case, we are free to reuse the existing parsing code. This saves us a few lines of code, but most importantly, it means that the logic for which files are examined is contained only in one place and cannot diverge. Signed-off-by: Jeff King <[email protected]>
1 parent 00b347d commit e895589

File tree

1 file changed

+2
-42
lines changed

1 file changed

+2
-42
lines changed

builtin/config.c

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,9 @@ static int collect_config(const char *key_, const char *value_, void *cb)
165165
static int get_value(const char *key_, const char *regex_)
166166
{
167167
int ret = CONFIG_GENERIC_ERROR;
168-
char *global = NULL, *xdg = NULL, *repo_config = NULL;
169-
const char *system_wide = NULL, *local;
170-
struct config_include_data inc = CONFIG_INCLUDE_INIT;
171-
config_fn_t fn;
172-
void *data;
173168
struct strbuf_list values = {0};
174169
int i;
175170

176-
local = given_config_file;
177-
if (!local) {
178-
local = repo_config = git_pathdup("config");
179-
if (git_config_system())
180-
system_wide = git_etc_gitconfig();
181-
home_config_paths(&global, &xdg, "config");
182-
}
183-
184171
if (use_key_regexp) {
185172
char *tl;
186173

@@ -229,32 +216,8 @@ static int get_value(const char *key_, const char *regex_)
229216
}
230217
}
231218

232-
fn = collect_config;
233-
data = &values;
234-
if (respect_includes) {
235-
inc.fn = fn;
236-
inc.data = data;
237-
fn = git_config_include;
238-
data = &inc;
239-
}
240-
241-
if (do_all && system_wide)
242-
git_config_from_file(fn, system_wide, data);
243-
if (do_all && xdg)
244-
git_config_from_file(fn, xdg, data);
245-
if (do_all && global)
246-
git_config_from_file(fn, global, data);
247-
if (do_all)
248-
git_config_from_file(fn, local, data);
249-
git_config_from_parameters(fn, data);
250-
if (!do_all && !values.nr)
251-
git_config_from_file(fn, local, data);
252-
if (!do_all && !values.nr && global)
253-
git_config_from_file(fn, global, data);
254-
if (!do_all && !values.nr && xdg)
255-
git_config_from_file(fn, xdg, data);
256-
if (!do_all && !values.nr && system_wide)
257-
git_config_from_file(fn, system_wide, data);
219+
git_config_with_options(collect_config, &values,
220+
given_config_file, respect_includes);
258221

259222
ret = !values.nr;
260223

@@ -267,9 +230,6 @@ static int get_value(const char *key_, const char *regex_)
267230
free(values.items);
268231

269232
free_strings:
270-
free(repo_config);
271-
free(global);
272-
free(xdg);
273233
free(key);
274234
if (key_regexp) {
275235
regfree(key_regexp);

0 commit comments

Comments
 (0)