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

Re: [PATCH 2/2] repository: move 'repository_format_worktree_config' to repo scope

From
Glen Choo <chooglen@google.com>
Date
May 25, 2023, 01:29 UTC
Message-ID
<kl6lv8ghxkpc.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<5ed9100a7707a529b309005419244d083cdc85ba.1684883872.git.gitgitgadget@gmail.com>

Here's a quick response on the config.c bits, I haven't looked through the global-removing parts closely yet. Rearranging the hunks for clarity...

"Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 24 quoted lines
> @@ -2667,11 +2670,14 @@ static void repo_read_config(struct repository *repo)
>  {
>  	struct config_options opts = { 0 };
>  	struct configset_add_data data = CONFIGSET_ADD_INIT;
> +	struct git_config_source config_source = { 0 };
>  
>  	opts.respect_includes = 1;
>  	opts.commondir = repo->commondir;
>  	opts.git_dir = repo->gitdir;
>  
> +	config_source.repo = repo;
> +
>  	if (!repo->config)
>  		CALLOC_ARRAY(repo->config, 1);
>  	else
> @@ -2681,7 +2687,7 @@ static void repo_read_config(struct repository *repo)
>  	data.config_set = repo->config;
>  	data.config_reader = &the_reader;
>  
> -	if (config_with_options(config_set_callback, &data, NULL, &opts) < 0)
> +	if (config_with_options(config_set_callback, &data, &config_source, &opts) < 0)
>  		/*
>  		 * config_with_options() normally returns only
>  		 * zero, as most errors are fatal, and

I think it would be better to pass a "struct repository" arg to config_with_options() instead of mocking a config_source to hold a .repo member. config_with_options() does double duty - it either discovers and reads the configs for the repo (system, global, worktree, etc), or it reads the config from just config_source. From this perspective, it doesn't make sense that the caller can pass config_source but config_with_options() will still discover and read all configs, and I think the only reason why this behavior is supported at all is that builtin/config.c sometimes "reads all config" and sometimes "reads from a single file", but sloppily passes a non-NULL "config_source" arg unconditionally.

Show 13 quoted lines
> diff --git a/config.c b/config.c
> index a93f7bfa3aa..9ce2ffff5e1 100644
> --- a/config.c
> +++ b/config.c
> @@ -2277,7 +2278,7 @@ int config_with_options(config_fn_t fn, void *data,
>  		data = &inc;
>  	}
>  
> -	if (config_source)
> +	if (config_source && config_source->scope != CONFIG_SCOPE_UNKNOWN)
>  		config_reader_set_scope(&the_reader, config_source->scope);
>  
>  	/*

The aforemented change would also let us get rid of this, which might not always be correct. I think there might be cases where the scope is actually unknown, but I'm not sure if we have any of those situations in-tree.

Show 12 quoted lines
> diff --git a/environment.c b/environment.c
> index 28d18eaca8e..6bd001efbde 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -42,7 +42,6 @@ int is_bare_repository_cfg = -1; /* unspecified */
>  int warn_ambiguous_refs = 1;
>  int warn_on_object_refname_ambiguity = 1;
>  int repository_format_precious_objects;
> -int repository_format_worktree_config;
>  const char *git_commit_encoding;
>  const char *git_log_output_encoding;
>  char *apply_default_whitespace;
As an aside, I'm really happy to lose another global :)
Previous: Victoria Dye via GitGitGadgetNext: Glen Choo
Message 6 of 29 in “Fix behavior of worktree config in submodules”
  1. 0/2 Fix behavior of worktree config in submodulesVictoria Dye via GitGitGadget, May 23, 2023
  2. 1/2 config: use gitdir to get worktree configVictoria Dye via GitGitGadget, May 23, 2023
  3. Glen ChooMay 25, 2023
  4. Derrick StoleeMay 25, 2023
  5. 2/2 repository: move 'repository_format_worktree_config' to repo scopeVictoria Dye via GitGitGadget, May 23, 2023
  6. Glen ChooMay 25, 2023
  7. Glen ChooMay 25, 2023
  8. Victoria DyeMay 25, 2023
  9. Derrick StoleeMay 25, 2023
  10. Junio C HamanoMay 24, 2023
  11. Glen ChooMay 25, 2023
  12. 0/3 Fix behavior of worktree config in submodulesVictoria Dye via GitGitGadget, May 26, 2023
  13. 1/3 config: use gitdir to get worktree configVictoria Dye via GitGitGadget, May 26, 2023
  14. 2/3 config: pass 'repo' directly to 'config_with_options()'Victoria Dye via GitGitGadget, May 26, 2023
  15. 3/3 repository: move 'repository_format_worktree_config' to repo scopeVictoria Dye via GitGitGadget, May 26, 2023
  16. Glen ChooMay 31, 2023
  17. Junio C HamanoJun 1, 2023
  18. Glen ChooJun 12, 2023
  19. Victoria DyeJun 7, 2023
  20. Glen ChooJun 12, 2023
  21. Victoria DyeJun 12, 2023
  22. Glen ChooJun 12, 2023
  23. setup: copy repository_format using helperGlen Choo, Jun 12, 2023
  24. Victoria DyeJun 13, 2023
  25. Glen ChooJun 13, 2023
  26. Junio C HamanoJun 13, 2023
  27. Derrick StoleeMay 26, 2023
  28. Glen ChooJun 13, 2023
  29. Victoria DyeJun 13, 2023

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.