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

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

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 12, 2026, 09:28 UTC
Message-ID
<aivRNR-Xss3JTNkc@pks.im>
In-Reply-To
<87wlw4yys1.fsf@emacs.iotcl.com>
On Fri, Jun 12, 2026 at 09:59:42AM +0200, Toon Claes wrote:
Show 34 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/setup.c b/setup.c
> > index 71fc6b33da..32f14a8688 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -795,10 +795,22 @@ 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;
> > +
> > +		/*
> > +		 * Furthermore, "core.worktree" is supposed to be ignored when
> > +		 * we have a commondir configured, unless it comes from the
> > +		 * per-worktree configuration.
> > +		 */
> >  		FREE_AND_NULL(candidate->work_tree);
> >  	}
> 
> Looking at the diff, this is really hard to understand. But your
> refactor makes sense and the after state is easier to comprehend.

Yeah, I'm in the same boat. Honestly, I really hope that our test suite has enough coverage so that this refactoring won't cause any significant regressions. Which isn't exactly a statement of confidence, but rather a statement of "oh boy, this is awfully complex and has lots of weird edge cases".

Show 11 quoted lines
> > @@ -2571,7 +2584,7 @@ static int create_default_files(struct repository *repo,
> >  		repo_settings_set_shared_repository(repo,
> >  						    init_shared_repository);
> >  
> > -	is_bare_repository_cfg = !work_tree;
> > +	repo->bare_cfg = !work_tree;
> 
> I'm curious, do we still need this? If I'm not mistaken, this function
> is called after check_and_apply_repository_format(), which calls
> apply_repository_format() and sets repo->bare_cfg too (see the diff
> above). Or is it explained by what Justin said[1]?

We can't drop this because after we've applied the format we call `repo_config()` with `git_default_core_config()`, which will potentially set the `bare_cfg` variable if "core.bare" is set.

Patrick
Previous: Toon ClaesNext: Patrick Steinhardt
Message 27 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.