diff options
author | Kristoffer Haugsbakk <code@khaugsbakk.name> | 2024-01-18 19:12:51 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-18 23:17:41 +0300 |
commit | c15129b699d9b225e916b84f542b9d3665fccc3d (patch) | |
tree | 39de440057530bc06a1533e7aefff7a891e7a631 /builtin | |
parent | ecffa3ed51aaa7af0119542ce31a1be5f40edcf9 (diff) |
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 'builtin')
-rw-r--r-- | builtin/config.c | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/builtin/config.c b/builtin/config.c index 6fff265581..08fe36d499 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -708,30 +708,11 @@ int cmd_config(int argc, const char **argv, const char *prefix) } if (use_global_config) { - char *user_config, *xdg_config; - - git_global_config_paths(&user_config, &xdg_config); - if (!user_config) - /* - * It is unknown if HOME/.gitconfig exists, so - * we do not know if we should write to XDG - * location; error out even if XDG_CONFIG_HOME - * is set and points at a sane location. - */ + given_config_source.file = git_global_config(); + if (!given_config_source.file) die(_("$HOME not set")); - given_config_source.scope = CONFIG_SCOPE_GLOBAL; - - if (access_or_warn(user_config, R_OK, 0) && - xdg_config && !access_or_warn(xdg_config, R_OK, 0)) { - given_config_source.file = xdg_config; - free(user_config); - } else { - given_config_source.file = user_config; - free(xdg_config); - } - } - else if (use_system_config) { + } else if (use_system_config) { given_config_source.file = git_system_config(); given_config_source.scope = CONFIG_SCOPE_SYSTEM; } else if (use_local_config) { |