aboutsummaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorKristoffer Haugsbakk <code@khaugsbakk.name>2024-01-18 17:12:51 +0100
committerJunio C Hamano <gitster@pobox.com>2024-01-18 12:17:41 -0800
commitc15129b699d9b225e916b84f542b9d3665fccc3d (patch)
tree39de440057530bc06a1533e7aefff7a891e7a631 /config.c
parentecffa3ed51aaa7af0119542ce31a1be5f40edcf9 (diff)
downloadgit-c15129b699d9b225e916b84f542b9d3665fccc3d.tar.gz
config: factor out global config file retrieval
Factor out code that retrieves the global config file so that we can use it in `gc.c` as well. Use the old name from the previous commit since this function acts functionally the same as `git_system_config` but for “global”. Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/config.c b/config.c
index ebc6a57e1c..3cfeb3d8bd 100644
--- a/config.c
+++ b/config.c
@@ -1987,6 +1987,26 @@ char *git_system_config(void)
return system_config;
}
+char *git_global_config(void)
+{
+ char *user_config, *xdg_config;
+
+ git_global_config_paths(&user_config, &xdg_config);
+ if (!user_config) {
+ free(xdg_config);
+ return NULL;
+ }
+
+ if (access_or_warn(user_config, R_OK, 0) && xdg_config &&
+ !access_or_warn(xdg_config, R_OK, 0)) {
+ free(user_config);
+ return xdg_config;
+ } else {
+ free(xdg_config);
+ return user_config;
+ }
+}
+
void git_global_config_paths(char **user_out, char **xdg_out)
{
char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL"));