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

Re: [PATCH 5/7] environment: split up concerns of `is_bare_repository_cfg`

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 11, 2026, 09:19 UTC
Message-ID
<aip9irJ7WBaICxDa@pks.im>
In-Reply-To
<ainesoUOuhspKxHF@denethor>
On Wed, Jun 10, 2026 at 05:22:04PM -0500, Justin Tobler wrote:
Show 14 quoted lines
> On 26/06/10 08:56AM, Patrick Steinhardt wrote:
> > diff --git a/builtin/init-db.c b/builtin/init-db.c
> > index 52aa92fb0a..566732c9f4 100644
> > --- a/builtin/init-db.c
> > +++ b/builtin/init-db.c
> > @@ -81,7 +81,7 @@ int cmd_init_db(int argc,
> >  	const char *template_dir = NULL;
> >  	char *template_dir_to_free = NULL;
> >  	unsigned int flags = 0;
> > -	int bare = is_bare_repository_cfg;
> > +	int bare = startup_info->force_bare_repository ? 1 : -1;
> 
> Any particular reason to continue mapping `force_bare_repository=false`
> to -1? Or was this to just minimize changes?

The `-1` value doesn't mean "false", but it rather means "undecided". The effect of this is that "core.bare" will eventually override this.

Show 27 quoted lines
> > diff --git a/setup.c b/setup.c
> > index 71fc6b33da..2b690da8ca 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -795,10 +795,16 @@ static int check_repository_format_gently(const char *gitdir,
> >  		has_common = 0;
> >  	}
> >  
> > -	if (!has_common) {
> > -		if (candidate->is_bare != -1)
> > -			is_bare_repository_cfg = candidate->is_bare;
> > -	} else {
> > +	if (startup_info->force_bare_repository) {
> > +		candidate->is_bare = 1;
> > +		FREE_AND_NULL(candidate->work_tree);
> > +	} else if (has_common) {
> > +		/*
> > +		 * When sharing a common dir with another repository (e.g. a
> > +		 * linked worktree), do not let this repository's config
> > +		 * dictate bareness; it is inherited from the main worktree.
> > +		 */
> > +		candidate->is_bare = -1;
> >  		FREE_AND_NULL(candidate->work_tree);
> 
> Previously, when there was a common dir, `candidate->work_tree` was left
> untouched, but now we are expclicitly setting it. I'm not sure I fully
> understand this change.

I cannot blame you. All of this logic is so unbelievably tangled and hard to follow.

In any case, I think you might have missed the fact that we `else if` branch is now `has_common` as compared to `!has_common`? To explain the different cases a bit:

  - When we have `force_bare_repository` we are being told that the
    repository should be treated as bare. So we set `is_bare` and also
    clear the work tree that may have been discovered.
  - When we have a commondir we know that we're in a worktree.
    Previously we did nothing in this case, and that had the implicit
    effect that `is_bare_repository_cfg` would remain at `-1`. So to
    match that behaviour we have to also reset the candidate's bareness
    to `-1`, so that we parse it via the repository's configuration at a
    later point in time.
    The other part here is that we also reset `candidate->work_tree`.
    This is because the expectation is that `$GIT_DIR/common` should
    override any "core.worktree" settings. Quoting git-config(1):
        If GIT_COMMON_DIR environment variable is set, core.worktree is
        ignored and not used for determining the root of working tree.
  - When we don't have a commondir we previosuly had to also adapt the
    global `is_bare_repository_cfg` variable. This part is not necessary
    anymore, so we basically just drop this case altogether.
Patrick
Previous: Justin ToblerNext: Justin Tobler
Message 12 of 33 in “setup: drop global state”
  1. 0/7 setup: drop global statePatrick Steinhardt, Jun 10, 2026
  2. 1/7 builtin/init: stop modifying global `git_work_tree_cfg` variablePatrick Steinhardt, Jun 10, 2026
  3. Justin ToblerJun 10, 2026
  4. 2/7 builtin/init: simplify logic to configure worktreePatrick Steinhardt, Jun 10, 2026
  5. Justin ToblerJun 10, 2026
  6. 3/7 setup: remove global `git_work_tree_cfg` variablePatrick Steinhardt, Jun 10, 2026
  7. Justin ToblerJun 10, 2026
  8. Patrick SteinhardtJun 11, 2026
  9. 4/7 builtin/init: stop modifying `is_bare_repository_cfg`Patrick Steinhardt, Jun 10, 2026
  10. 5/7 environment: split up concerns of `is_bare_repository_cfg`Patrick Steinhardt, Jun 10, 2026
  11. Justin ToblerJun 10, 2026
  12. Patrick SteinhardtJun 11, 2026
  13. Justin ToblerJun 11, 2026
  14. 6/7 environment: stop using `the_repository` in `is_bare_repository()`Patrick Steinhardt, Jun 10, 2026
  15. 7/7 treewide: drop USE_THE_REPOSITORY_VARIABLEPatrick Steinhardt, Jun 10, 2026
  16. Justin ToblerJun 10, 2026
  17. Toon ClaesJun 12, 2026
  18. 0/7 setup: drop global statePatrick Steinhardt, Jun 11, 2026
  19. 1/7 builtin/init: stop modifying global `git_work_tree_cfg` variablePatrick Steinhardt, Jun 11, 2026
  20. Toon ClaesJun 12, 2026
  21. Patrick SteinhardtJun 12, 2026
  22. 2/7 builtin/init: simplify logic to configure worktreePatrick Steinhardt, Jun 11, 2026
  23. 3/7 setup: remove global `git_work_tree_cfg` variablePatrick Steinhardt, Jun 11, 2026
  24. 4/7 builtin/init: stop modifying `is_bare_repository_cfg`Patrick Steinhardt, Jun 11, 2026
  25. 5/7 environment: split up concerns of `is_bare_repository_cfg`Patrick Steinhardt, Jun 11, 2026
  26. Toon ClaesJun 12, 2026
  27. Patrick SteinhardtJun 12, 2026
  28. 6/7 environment: stop using `the_repository` in `is_bare_repository()`Patrick Steinhardt, Jun 11, 2026
  29. 7/7 treewide: drop USE_THE_REPOSITORY_VARIABLEPatrick Steinhardt, Jun 11, 2026
  30. Justin ToblerJun 11, 2026
  31. Toon ClaesJun 12, 2026
  32. Patrick SteinhardtJun 12, 2026
  33. Toon ClaesJun 16, 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.