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 <peff@peff.net>

Jeff King committed Oct 23, 2012 at 18:00 UTC e89558988305c3e912c0674faeb814e44563f7fd
1 file changed +2 -42
builtin/config.c
+2 -42
@@ -165,22 +165,9 @@ static int collect_config(const char *key_, const char *value_, void *cb)
165 static int get_value(const char *key_, const char *regex_)
166 {
167 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;
168 struct strbuf_list values = {0};
169 int i;
170
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 -
171 if (use_key_regexp) {
172 char *tl;
173
@@ -229,32 +216,8 @@ static int get_value(const char *key_, const char *regex_)
216 }
217 }
218
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);
221
222 ret = !values.nr;
223
@@ -267,9 +230,6 @@ static int get_value(const char *key_, const char *regex_)
230 free(values.items);
231
232 free_strings:
270 - free(repo_config);
271 - free(global);
272 - free(xdg);
233 free(key);
234 if (key_regexp) {
235 regfree(key_regexp);