git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.
Previous: Kristoffer HaugsbakkNext: Kristoffer Haugsbakk
Message 28 of 33 in “maintenance: use XDG config if it exists”
  1. 0/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Oct 18, 2023
  2. 1/4 config: format newlinesKristoffer Haugsbakk, Oct 18, 2023
  3. 2/4 config: rename global config functionKristoffer Haugsbakk, Oct 18, 2023
  4. 3/4 config: factor out global config file retrievalKristoffer Haugsbakk, Oct 18, 2023
  5. Patrick SteinhardtOct 23, 2023
  6. Taylor BlauOct 23, 2023
  7. Kristoffer HaugsbakkOct 24, 2023
  8. Patrick SteinhardtOct 25, 2023
  9. Kristoffer HaugsbakkOct 25, 2023
  10. Patrick SteinhardtOct 25, 2023
  11. Junio C HamanoOct 27, 2023
  12. 4/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Oct 18, 2023
  13. Patrick SteinhardtOct 23, 2023
  14. Eric SunshineOct 23, 2023
  15. 0/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Jan 14, 2024
  16. 1/4 config: format newlinesKristoffer Haugsbakk, Jan 14, 2024
  17. 2/4 config: rename global config functionKristoffer Haugsbakk, Jan 14, 2024
  18. 3/4 config: factor out global config file retrievalKristoffer Haugsbakk, Jan 14, 2024
  19. Junio C HamanoJan 16, 2024
  20. Kristoffer HaugsbakkJan 16, 2024
  21. Patrick SteinhardtJan 19, 2024
  22. Kristoffer HaugsbakkJan 19, 2024
  23. Patrick SteinhardtJan 19, 2024
  24. Junio C HamanoJan 19, 2024
  25. Junio C HamanoJan 19, 2024
  26. rsbecker@nexbridge.comJan 19, 2024
  27. 4/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Jan 14, 2024
  28. Junio C HamanoJan 16, 2024
  29. 0/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Jan 18, 2024
  30. 1/4 config: format newlinesKristoffer Haugsbakk, Jan 18, 2024
  31. 2/4 config: rename global config functionKristoffer Haugsbakk, Jan 18, 2024
  32. 3/4 config: factor out global config file retrievalKristoffer Haugsbakk, Jan 18, 2024
  33. 4/4 maintenance: use XDG config if it existsKristoffer Haugsbakk, Jan 18, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.