Re: [PATCH v2 4/4] maintenance: use XDG config if it exists
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 16, 2024, 21:52 UTC
- Message-ID
- <xmqq7ck9ymi3.fsf@gitster.g>
- In-Reply-To
- <8bd67c5bf01ca10fbf575dfa2cf88f8c88b48276.1705267839.git.code@khaugsbakk.name>
Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
Show 24 quoted lines
> diff --git a/builtin/gc.c b/builtin/gc.c
> index c078751824c..cb80ced6cb5 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1543,19 +1543,18 @@ static int maintenance_register(int argc, const char **argv, const char *prefix)
>
> if (!found) {
> int rc;
> - char *user_config = NULL, *xdg_config = NULL;
> + char *global_config_file = NULL;
>
> if (!config_file) {
> - git_global_config_paths(&user_config, &xdg_config);
> - config_file = user_config;
> - if (!user_config)
> - die(_("$HOME not set"));
> + global_config_file = git_global_config();
> + config_file = global_config_file;
> }
> + if (!config_file)
> + die(_("$HOME not set"));
> rc = git_config_set_multivar_in_file_gently(
> config_file, "maintenance.repo", maintpath,
> CONFIG_REGEX_NONE, 0);OK. We used to ask for both user and xdg and without using xdg at all, as long as $HOME is set, we used $HOME/.gitconfig even if it did not exist.
What we want to happen is we pick XDG is XDG exists *and* $HOME/.gitconfig does not. And that is exactly what git_global_config() gives us.
Nicely done.
Show 20 quoted lines
> @@ -1612,18 +1611,18 @@ static int maintenance_unregister(int argc, const char **argv, const char *prefi
>
> if (found) {
> int rc;
> - char *user_config = NULL, *xdg_config = NULL;
> + char *global_config_file = NULL;
> +
> if (!config_file) {
> - git_global_config_paths(&user_config, &xdg_config);
> - config_file = user_config;
> - if (!user_config)
> - die(_("$HOME not set"));
> + global_config_file = git_global_config();
> + config_file = global_config_file;
> }
> + if (!config_file)
> + die(_("$HOME not set"));
> rc = git_config_set_multivar_in_file_gently(
> config_file, key, NULL, maintpath,
> CONFIG_FLAGS_MULTI_REPLACE | CONFIG_FLAGS_FIXED_VALUE);Ditto.