Re: [PATCH 09/18] setup: stop using `the_repository` in `setup_work_tree()`
- From
Elijah Newren <newren@gmail.com>
- Date
- Apr 18, 2026, 01:11 UTC
- Message-ID
- <CABPp-BHOvDaWXXDnpPsoDTe-En7T4LUaVqcJZ5Jst8zaQ-mrTg@mail.gmail.com>
- In-Reply-To
- <20260330-pks-setup-wo-the-repository-v1-9-0d2e822837aa@pks.im>
On Mon, Mar 30, 2026 at 6:30 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 12 quoted lines
> > 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>
Show 9 quoted lines
> 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....
Show 12 quoted lines
> 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?