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

Re: [PATCH 3/7] setup: remove global `git_work_tree_cfg` variable

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 11, 2026, 06:36 UTC
Message-ID
<aipXZUrDcM1gOLsz@pks.im>
In-Reply-To
<ainXM84fGggtEZzM@denethor>
On Wed, Jun 10, 2026 at 04:52:12PM -0500, Justin Tobler wrote:
Show 36 quoted lines
> On 26/06/10 08:56AM, Patrick Steinhardt wrote:
> > diff --git a/setup.c b/setup.c
> > index 52228b42a1..71fc6b33da 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -31,9 +31,6 @@ enum allowed_bare_repo {
> >  	ALLOWED_BARE_REPO_ALL,
> >  };
> >  
> > -/* This is set by setup_git_directory_gently() and/or git_default_config() */
> > -static char *git_work_tree_cfg;
> > -
> >  static struct startup_info the_startup_info;
> >  struct startup_info *startup_info = &the_startup_info;
> >  const char *tmp_original_cwd;
> > @@ -799,13 +796,10 @@ static int check_repository_format_gently(const char *gitdir,
> >  	}
> >  
> >  	if (!has_common) {
> > -		if (candidate->is_bare != -1) {
> > +		if (candidate->is_bare != -1)
> >  			is_bare_repository_cfg = candidate->is_bare;
> > -		}
> > -		if (candidate->work_tree) {
> > -			free(git_work_tree_cfg);
> > -			git_work_tree_cfg = xstrdup(candidate->work_tree);
> 
> Ok, we no longer set `git_work_tree_cfg` in favor of just relying on the
> worktree specified in the repository format.
> 
> > -		}
> > +	} else {
> > +		FREE_AND_NULL(candidate->work_tree);
> 
> Huh, we were not previously freeing the worktree here, but I assume this
> to avoid a resource leak?

This is in fact a required change. Before this patch this here was the place where we populated `git_work_tree_cfg`, and that variable was then later on applied to the repository. So the implicit `else` branch was basically just `git_work_tree_cfg = NULL`, but we didn't have to do that as it already was set to `NULL`.

With the new code though we're not setting `git_work_tree_cfg` anymore and instead directly populate from `candidate->work_tree`. But that also means that we now have to clear that variable to retain previous semantics.

I'll add an explanation to the commit message.
Patrick
Previous: Justin ToblerNext: Patrick Steinhardt
Message 8 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.