Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Tian Yuchen <cat@malon.dev>
Cc: git@vger.kernel.org,
	Christian Couder <christian.couder@gmail.com>,
	Ayush Chandekar <ayu.chandekar@gmail.com>,
	Olamide Caleb Bello <belkid98@gmail.com>
Subject: Re: [PATCH v3 1/3] environment: drop redundant NULL checks in config getters
Date: Fri, 11 Sep 2026 08:22:22 +0200	[thread overview]
Message-ID: <aqOeHlPWer60LcoO@pks.im> (raw)
In-Reply-To: <20260807085932.3958759-2-cat@malon.dev>

On Fri, Aug 07, 2026 at 04:59:30PM +0800, Tian Yuchen wrote:
> 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.

> 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

  reply	other threads:[~2026-09-11  6:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 11:53 [PATCH 0/3] environment: clean up repository config handling Tian Yuchen
2026-08-05 11:53 ` [PATCH 1/3] environment: simplify repository config getters Tian Yuchen
2026-08-05 21:49   ` Junio C Hamano
2026-08-05 11:53 ` [PATCH 2/3] environment: clarify repository config getter documentation Tian Yuchen
2026-08-05 21:38   ` Junio C Hamano
2026-08-06  8:49     ` Tian Yuchen
2026-08-05 11:53 ` [PATCH 3/3] environment: reorder variables in repo_config_values structure Tian Yuchen
2026-08-05 21:47   ` Junio C Hamano
2026-08-06  8:44     ` Tian Yuchen
2026-08-06 16:42       ` Junio C Hamano
2026-08-07  8:26         ` Tian Yuchen
2026-08-06  9:25 ` [PATCH v2 0/3] environment: clean up repository config handling Tian Yuchen
2026-08-06  9:25   ` [PATCH v2 1/3] environment: simplify repository config getters Tian Yuchen
2026-08-06 16:50     ` Junio C Hamano
2026-08-07  8:30       ` Tian Yuchen
2026-08-06  9:25   ` [PATCH v2 2/3] environment: clarify repository config getter documentation Tian Yuchen
2026-08-06 16:54     ` Junio C Hamano
2026-08-06  9:25   ` [PATCH v2 3/3] environment: remove inaccurate repo_config_values comments Tian Yuchen
2026-08-07  8:59 ` [PATCH v3 0/3] environment: clean up repository config handling Tian Yuchen
2026-08-07  8:59   ` [PATCH v3 1/3] environment: drop redundant NULL checks in config getters Tian Yuchen
2026-09-11  6:22     ` Patrick Steinhardt [this message]
2026-08-07  8:59   ` [PATCH v3 2/3] environment: clarify repository config getter documentation Tian Yuchen
2026-08-07  8:59   ` [PATCH v3 3/3] environment: remove inaccurate repo_config_values comments Tian Yuchen
2026-08-07 11:04   ` [PATCH v3 0/3] environment: clean up repository config handling Patrick Steinhardt
2026-08-07 21:11     ` Junio C Hamano
2026-08-10  5:50       ` Patrick Steinhardt
2026-08-26 19:56         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aqOeHlPWer60LcoO@pks.im \
    --to=ps@pks.im \
    --cc=ayu.chandekar@gmail.com \
    --cc=belkid98@gmail.com \
    --cc=cat@malon.dev \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox