Subject: Re: [PATCH 0/2] worktree_git_path(): remove repository argument

From: Shreyansh Paliwal <[email-masked]>
Date: Tue, 17 Feb 2026 22:15:49 +0530

> On 17/02/2026 10:12, Shreyansh Paliwal wrote:
> >> On 14/02/2026 14:30, Phillip Wood wrote:
> >>>
> >>> I think that we should add a new function
> >>>
> >>> struct worktree *get_current_worktree(struct repository*);
> >>>
> >>> to worktree.c that constructs a struct worktree using repo->gitdir etc.
> >>> The worktree id is the last path component of repo->gitdir when the
> >>> repo->gitdir and repo->commondir differ, otherwise it is NULL. Then we
> >>> can use that function to get the current worktree rather than passing
> >>> NULL when we call wt_status_check_{rebase,bisect} from
> >>> wt_status_get_state().
> >>
> >> Here's what that looks like, the first patch adds
> >> get_worktree_from_repository() and uses it to avoid passing a NULL
> >> worktree to worktree_git_path(). The second patch then removes the
> >> repository argument from that function and always uses wt->repo instead.
> >>
> >> Shreyansh - I think your patches to clean up wt-status.c can probably proceed
> >> separately to these if you remove the changes to
> >> wt_status_check_{bisect,rebase}().
> >
> > Cool. I'll send a revised version on the original thread.
>
> Great, I hope I'm not stepping on your toes posting these patches. By
> the time I'd worked out what was needed and checked all the callers were
> passing a non-NULL worktree argument I had the code changes and commit
> messages so I thought I'd post them.

Not at all, I’m glad you posted them. They clarified the right direction
and are logically more fit.
I got to learn a lot about the worktree API while working on this,
so that was very helpful. Thanks :)

Best,
Shreyansh