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

Re: [PATCH 09/18] setup: stop using `the_repository` in `setup_work_tree()`

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 20, 2026, 07:06 UTC
Message-ID
<aeXQcDF-wHT4wEG-@pks.im>
In-Reply-To
<CABPp-BHOvDaWXXDnpPsoDTe-En7T4LUaVqcJZ5Jst8zaQ-mrTg@mail.gmail.com>
On Fri, Apr 17, 2026 at 06:11:48PM -0700, Elijah Newren wrote:
Show 52 quoted lines
> On Mon, Mar 30, 2026 at 6:30 AM Patrick Steinhardt <ps@pks.im> wrote:
> >
> > Stop using `the_repository` in `setup_work_tree()` and instead accept
> > the repository as a parameter. The injection of `the_repository` is thus
> > bumped one level higher, where callers now pass it in explicitly.
> >
> > Note that the function tracks bogus worktree configuration via a global
> > variable. If we have bogus configuration, and if later on some caller
> > tries to setup a worktree, then we'll die instead.
> >
> > Of course, tracking this as a global variable doesn't make sense anymore
> > now that we can set up worktrees for arbitrary repositories. Move the
> > variable into `struct repository` instead.
> 
> Okay, we don't want a global, makes sense.
> 
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> 
> > diff --git a/setup.c b/setup.c
> > index dca32addae..64a030c6cd 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -26,7 +26,6 @@
> >  #include "trace2.h"
> >  #include "worktree.h"
> >
> > -static int work_tree_config_is_bogus;
> 
> So, we removed this global....
> 
> >  enum allowed_bare_repo {
> >         ALLOWED_BARE_REPO_EXPLICIT = 0,
> >         ALLOWED_BARE_REPO_ALL,
> > @@ -485,7 +484,7 @@ int is_inside_work_tree(struct repository *repo)
> >         return is_inside_dir(strbuf_realpath(&buf, worktree, 1));
> >  }
> >
> > -void setup_work_tree(void)
> > +void setup_work_tree(struct repository *repo)
> >  {
> >         const char *work_tree;
> >         static int initialized = 0;
> 
> ...but we left this one...
> 
> > @@ -493,10 +492,10 @@ void setup_work_tree(void)
> >         if (initialized)
> >                 return;
> 
> ...and because of this other global, we still can only set up one work
> tree in the process anyway.  Should 'initialized' also be moved to a
> field within repo?

Good catch. I thought I fixed this instance in a later commit or in the next patch series, but I seemingly don't. Will adapt, thanks!

Patrick
Previous: Elijah NewrenNext: Patrick Steinhardt
Message 16 of 31 in “setup: drop uses of `the_repository`”
  1. 00/18 setup: drop uses of `the_repository`Patrick Steinhardt, Mar 30, 2026
  2. 01/18 setup: replace use of `the_repository` in static functionsPatrick Steinhardt, Mar 30, 2026
  3. 02/18 setup: stop using `the_repository` in `is_inside_worktree()`Patrick Steinhardt, Mar 30, 2026
  4. Karthik NayakApr 9, 2026
  5. 03/18 setup: stop using `the_repository` in `is_inside_git_dir()`Patrick Steinhardt, Mar 30, 2026
  6. Karthik NayakApr 9, 2026
  7. Patrick SteinhardtApr 13, 2026
  8. Junio C HamanoApr 13, 2026
  9. 04/18 setup: stop using `the_repository` in `prefix_path()`Patrick Steinhardt, Mar 30, 2026
  10. 05/18 setup: stop using `the_repository` in `path_inside_repo()`Patrick Steinhardt, Mar 30, 2026
  11. 06/18 setup: stop using `the_repository` in `verify_filename()`Patrick Steinhardt, Mar 30, 2026
  12. 07/18 setup: stop using `the_repository` in `verify_non_filename()`Patrick Steinhardt, Mar 30, 2026
  13. 08/18 setup: stop using `the_repository` in `enter_repo()`Patrick Steinhardt, Mar 30, 2026
  14. 09/18 setup: stop using `the_repository` in `setup_work_tree()`Patrick Steinhardt, Mar 30, 2026
  15. Elijah NewrenApr 18, 2026
  16. Patrick SteinhardtApr 20, 2026
  17. 10/18 setup: stop using `the_repository` in `set_git_work_tree()`Patrick Steinhardt, Mar 30, 2026
  18. Elijah NewrenApr 18, 2026
  19. Patrick SteinhardtApr 20, 2026
  20. 11/18 setup: stop using `the_repository` in `setup_git_env()`Patrick Steinhardt, Mar 30, 2026
  21. 12/18 setup: stop using `the_repository` in `setup_git_directory_gently()`Patrick Steinhardt, Mar 30, 2026
  22. 13/18 setup: stop using `the_repository` in `setup_git_directory()`Patrick Steinhardt, Mar 30, 2026
  23. 14/18 setup: stop using `the_repository` in `upgrade_repository_format()`Patrick Steinhardt, Mar 30, 2026
  24. 15/18 setup: stop using `the_repository` in `check_repository_format()`Patrick Steinhardt, Mar 30, 2026
  25. Elijah NewrenApr 18, 2026
  26. Patrick SteinhardtApr 20, 2026
  27. 16/18 setup: stop using `the_repository` in `initialize_repository_version()`Patrick Steinhardt, Mar 30, 2026
  28. 17/18 setup: stop using `the_repository` in `create_reference_database()`Patrick Steinhardt, Mar 30, 2026
  29. 18/18 setup: stop using `the_repository` in `init_db()`Patrick Steinhardt, Mar 30, 2026
  30. Karthik NayakApr 9, 2026
  31. Patrick SteinhardtApr 13, 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.