Skip to content

Commit 1e06eb9

Browse files
pks-tgitster
authored andcommitted
config: unify code paths to get global config paths
There's two callsites which assemble global config paths, once in the config loading code and once in the git-config(1) builtin. We're about to implement a way to override global config paths via an environment variable which would require us to adjust both sites. Unify both code paths into a single `git_global_config()` function which returns both paths for `~/.gitconfig` and the XDG config file. This will make the subsequent patch which introduces the new envvar easier to implement. No functional changes are expected from this patch. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c62a999 commit 1e06eb9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

builtin/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
671671
}
672672

673673
if (use_global_config) {
674-
char *user_config = expand_user_path("~/.gitconfig", 0);
675-
char *xdg_config = xdg_config_home("config");
674+
char *user_config, *xdg_config;
676675

676+
git_global_config(&user_config, &xdg_config);
677677
if (!user_config)
678678
/*
679679
* It is unknown if HOME/.gitconfig exists, so

config.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,12 @@ char *git_system_config(void)
18491849
return system_path(ETC_GITCONFIG);
18501850
}
18511851

1852+
void git_global_config(char **user_config, char **xdg_config)
1853+
{
1854+
*user_config = expand_user_path("~/.gitconfig", 0);
1855+
*xdg_config = xdg_config_home("config");
1856+
}
1857+
18521858
/*
18531859
* Parse environment variable 'k' as a boolean (in various
18541860
* possible spellings); if missing, use the default value 'def'.
@@ -1881,8 +1887,8 @@ static int do_git_config_sequence(const struct config_options *opts,
18811887
{
18821888
int ret = 0;
18831889
char *system_config = git_system_config();
1884-
char *xdg_config = xdg_config_home("config");
1885-
char *user_config = expand_user_path("~/.gitconfig", 0);
1890+
char *xdg_config = NULL;
1891+
char *user_config = NULL;
18861892
char *repo_config;
18871893
enum config_scope prev_parsing_scope = current_parsing_scope;
18881894

@@ -1900,6 +1906,8 @@ static int do_git_config_sequence(const struct config_options *opts,
19001906
ret += git_config_from_file(fn, system_config, data);
19011907

19021908
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
1909+
git_global_config(&user_config, &xdg_config);
1910+
19031911
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
19041912
ret += git_config_from_file(fn, xdg_config, data);
19051913

config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ int config_error_nonbool(const char *);
327327
#endif
328328

329329
char *git_system_config(void);
330+
void git_global_config(char **user, char **xdg);
330331

331332
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
332333

0 commit comments

Comments
 (0)