Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2021-04-19 15:31:12 +0300
committerJunio C Hamano <gitster@pobox.com>2021-04-20 00:16:59 +0300
commit1e06eb9b5dc9c663c2a60a2ca63e218b41a765e8 (patch)
treed89055322ac685bdec26afbae8b5d189b5fde15d /config.c
parentc62a999c6e595692ee3bd8ff1e9435491872a79c (diff)
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>
Diffstat (limited to 'config.c')
-rw-r--r--config.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/config.c b/config.c
index 3199b1b30c..8900d96cb6 100644
--- a/config.c
+++ b/config.c
@@ -1849,6 +1849,12 @@ char *git_system_config(void)
return system_path(ETC_GITCONFIG);
}
+void git_global_config(char **user_config, char **xdg_config)
+{
+ *user_config = expand_user_path("~/.gitconfig", 0);
+ *xdg_config = xdg_config_home("config");
+}
+
/*
* Parse environment variable 'k' as a boolean (in various
* possible spellings); if missing, use the default value 'def'.
@@ -1881,8 +1887,8 @@ static int do_git_config_sequence(const struct config_options *opts,
{
int ret = 0;
char *system_config = git_system_config();
- char *xdg_config = xdg_config_home("config");
- char *user_config = expand_user_path("~/.gitconfig", 0);
+ char *xdg_config = NULL;
+ char *user_config = NULL;
char *repo_config;
enum config_scope prev_parsing_scope = current_parsing_scope;
@@ -1900,6 +1906,8 @@ static int do_git_config_sequence(const struct config_options *opts,
ret += git_config_from_file(fn, system_config, data);
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
+ git_global_config(&user_config, &xdg_config);
+
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
ret += git_config_from_file(fn, xdg_config, data);