git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:53 UTC

Re: [PATCH v3 1/3] environment: drop redundant NULL checks in config getters

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 11, 2026, 06:22 UTC
Message-ID
<aqOeHlPWer60LcoO@pks.im>
In-Reply-To
<20260807085932.3958759-2-cat@malon.dev>
On Fri, Aug 07, 2026 at 04:59:30PM +0800, Tian Yuchen wrote:
Show 5 quoted lines
> These repository config getters require a valid repository pointer.
> While an uninitialized repository is a valid state and is handled by
> returning default values, passing NULL is a programming error.
> 
> Drop the NULL checks so that invalid callers are not silently accepted.

I'm not quite convinced that having these checks in the first place is a good idea. The single biggest problem is that we silently ignore the settings in case the repository just happens to be uninitialized, and we wouldn't ever notice.

On top of that, we even fall back to the wrong value: if we don't have a repository, we shouldn't fall back to the default values. Instead, shouldn't we fall back to the global- or system-level configuration?

I'm not convinced that this design is correct. What I think we should be doing is:

  - Have the functions accept an optional repository.
  - If a repository is passed, then we verify that it is initialized.
    If not, we BUG.
  - If we haven't yet read the configuration for that repository, then
    we automatically do it so that we can also pass a repository other
    than `the_repository`.
  - If no repository is passed, then we populate a global variable that
    contains the system- and global-level configuration and return that
    value instead.

That'd work both in the context where we have a repository and where we don't have one, and we'd detect the edge case where we have a repository that is uninitialized.

Show 15 quoted lines
> diff --git a/environment.c b/environment.c
> index 76ee65e62b..f5628b6758 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -119,23 +119,23 @@ int is_bare_repository(struct repository *repo)
>  
>  int repo_protect_ntfs(struct repository *repo)
>  {
> -	return (repo && repo->initialized) ?
> -		repo_config_values(repo)->protect_ntfs :
> -		PROTECT_NTFS_DEFAULT;
> +	return repo->initialized
> +		? repo_config_values(repo)->protect_ntfs
> +		: PROTECT_NTFS_DEFAULT;
>  }

So I think if we want to lose these checks, we should lose both of them and require the repository to be initialized. But I feel like this whole subsystem needs a bit of a redesign before we can continue iterating on it.

Patrick
Previous: Junio C Hamano
Message 27 of 27 in “environment: clean up repository config handling”
  1. 0/3 environment: clean up repository config handlingTian Yuchen, Aug 5, 2026
  2. 2/3 environment: clarify repository config getter documentationTian Yuchen, Aug 5, 2026
  3. 1/3 environment: simplify repository config gettersTian Yuchen, Aug 5, 2026
  4. 3/3 environment: reorder variables in repo_config_values structureTian Yuchen, Aug 5, 2026
  5. Junio C HamanoAug 5, 2026
  6. Junio C HamanoAug 5, 2026
  7. Junio C HamanoAug 5, 2026
  8. Tian YuchenAug 6, 2026
  9. Tian YuchenAug 6, 2026
  10. 0/3 environment: clean up repository config handlingTian Yuchen, Aug 6, 2026
  11. 1/3 environment: simplify repository config gettersTian Yuchen, Aug 6, 2026
  12. 2/3 environment: clarify repository config getter documentationTian Yuchen, Aug 6, 2026
  13. 3/3 environment: remove inaccurate repo_config_values commentsTian Yuchen, Aug 6, 2026
  14. Junio C HamanoAug 6, 2026
  15. Junio C HamanoAug 6, 2026
  16. Junio C HamanoAug 6, 2026
  17. Tian YuchenAug 7, 2026
  18. Tian YuchenAug 7, 2026
  19. 0/3 environment: clean up repository config handlingTian Yuchen, Aug 7, 2026
  20. 1/3 environment: drop redundant NULL checks in config gettersTian Yuchen, Aug 7, 2026
  21. 2/3 environment: clarify repository config getter documentationTian Yuchen, Aug 7, 2026
  22. 3/3 environment: remove inaccurate repo_config_values commentsTian Yuchen, Aug 7, 2026
  23. Patrick SteinhardtAug 7, 2026
  24. Junio C HamanoAug 7, 2026
  25. Patrick SteinhardtAug 10, 2026
  26. Junio C HamanoAug 26, 2026
  27. Patrick SteinhardtSep 11, 2026

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.