Subject: Re: [Question] check_repository_format_gently() is not side-effect-free

From: Patrick Steinhardt <[email-masked]>
Date: Fri, 20 Mar 2026 07:07:07 +0100

On Fri, Mar 20, 2026 at 08:24:09AM +0800, Tian Yuchen wrote:
> On 3/20/26 02:07, Junio C Hamano wrote:
> > The verb "check" does not imply side-effect-free.  By checking, each
> > of these functions tries to achieve something, and the way the
> > result of their work is conveyed back to the caller may not
> > necessarily be only by their return values.
> > 
> > The adverb "gently" in this codebase typically means "the variant
> > without gently signals problems by dying.  Instead of dying, return
> > to the caller with error code, so that the caller can decide to
> > die".
> 
> Ah, I see. I guess I took it too literally. Thank you for clarification!
> 
> Setting the semantics aside, the problem remains: I still think the setup
> method here isn't quite right. It creates a bottleneck for eventually
> handling multiple repositories in the same process without data races.
> 
> Do you think this is worth a patch?

Yes, I think that the whole of "setup.c" is something we will want to
refactor eventually so that it does not modify global state anymore. So
it's not only `check_repository_format_gently()`, but also lots of other
functionality in that file. The motivation is not only being able to set
up multiple repositories, but also making the code overall easier to
understand.

That being said, I'll give a small warning that it's probably
non-trivial to refactor this subystem :)

Thanks!

Patrick