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

Re: [RFC PATCH] config: teach `repo_config()` to allow `repo` to be NULL

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Feb 28, 2025, 10:56 UTC
Message-ID
<4e21312d-0d9a-404a-a2e0-0e2fcc681ad6@gmail.com>
In-Reply-To
<20250227175456.1129840-1-usmanakinyemi202@gmail.com>
Hi Usman
On 27/02/2025 17:54, Usman Akinyemi wrote:
Show 11 quoted lines
> The `repo` value can be NULL if a builtin command is run outside
> any repository. The current implementation of `repo_config()` will
> fail if `repo` is NULL.
> 
> If the `repo` is NULL the `repo_config()` can ignore the repository
> configuration but it should read the other configuration sources like
> the system-side configuration instead of failing.
> 
> Teach the `repo_config()` to allow `repo` to be NULL by calling the
> `read_very_early_config()` which read config but only enumerate system
> and global settings.

" Thanks for working on this, I like the idea but looking at read_very_early_config() it sets "opts.ignore_cmdline = 1" which means that this will ignore any config options passed with "git -c key=value". I think it would be better to call config_with_options() with the appropriate options directly.

For this to work all the commands that run outside a repository would have to read the config via repo_config(), and take care not to call any of the repo_config_get_*() functions. They mostly seem to do that but "git for-each-repo" calls repo_config_get_string_multi() - it should be easy enough to convert that to a callback when that command is updated to stop using "the_repository"

Best Wishes
Phillip
Show 37 quoted lines
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Mentored-by: Christian Couder <chriscool@tuxfamily.org>
> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
> ---
>   config.c | 4 ++++
>   config.h | 3 +++
>   2 files changed, 7 insertions(+)
> 
> diff --git a/config.c b/config.c
> index 36f76fafe5..c5181fd23b 100644
> --- a/config.c
> +++ b/config.c
> @@ -2526,6 +2526,10 @@ void repo_config_clear(struct repository *repo)
>   
>   void repo_config(struct repository *repo, config_fn_t fn, void *data)
>   {
> +	if (!repo) {
> +		read_very_early_config(fn, data);
> +		return;
> +	}
>   	git_config_check_init(repo);
>   	configset_iter(repo->config, fn, data);
>   }
> diff --git a/config.h b/config.h
> index 5c730c4f89..1e5b22dfc4 100644
> --- a/config.h
> +++ b/config.h
> @@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data);
>    * repo-specific one; by overwriting, the higher-priority repo-specific
>    * value is left at the end).
>    *
> + * In cases where the repository variable is NULL, repo_config() will
> + * call read_early_config().
> + *
>    * Unlike git_config_from_file(), this function respects includes.
>    */
>   void repo_config(struct repository *r, config_fn_t fn, void *);
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 9 in “config: teach `repo_config()` to allow `repo` to be NULL”
  1. config: teach `repo_config()` to allow `repo` to be NULLUsman Akinyemi, Feb 27, 2025
  2. Eric SunshineFeb 27, 2025
  3. Junio C HamanoFeb 27, 2025
  4. Phillip WoodFeb 28, 2025
  5. Junio C HamanoFeb 28, 2025
  6. Usman AkinyemiFeb 28, 2025
  7. Junio C HamanoMar 1, 2025
  8. Usman AkinyemiMar 3, 2025
  9. Junio C HamanoMar 3, 2025

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.