Re: [PATCH 1/2] wt-status: avoid passing NULL worktree
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Feb 18, 2026, 14:19 UTC
- Message-ID
- <d881edeb-d73b-43ba-bdb3-1b664e1cb882@gmail.com>
- In-Reply-To
- <CAOLa=ZQKLqFn4w3s7PD87FZ_120gohoqKX5c3uLKo2vASsbxfA@mail.gmail.com>
On 17/02/2026 17:46, Karthik Nayak wrote:
Show 9 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes: >> From: Phillip Wood <phillip.wood@dunelm.org.uk> >> >> This updates the only callers that pass a NULL worktree to >> worktree_git_path(). >> > > I was thinking surely there must be other places where we also pass NULL > for worktree, but doesn't seem like there are any such instances.
Yes, I was pleasantly surprised there weren't more sites to convert.
Show 12 quoted lines
>> +struct worktree *get_worktree_from_repository(struct repository *repo)
>> +{
>> + struct worktree *wt = xcalloc(1, sizeof(*wt));
>> + char *gitdir = absolute_pathdup(repo->gitdir);
>> + char *commondir = absolute_pathdup(repo->commondir);
>> +
>> + wt->repo = repo;
>> + if (repo->worktree)
>> + wt->path = absolute_pathdup(repo->worktree);
>
> Shouldn't this always be set? I guess my question is, will
> `repo->worktree` ever be NULL?Oh, wt->path should never be NULL. repo->worktree is NULL in bare repositories but then we should use repo->gitdir as the worktree path.
Show 10 quoted lines
>> + wt->is_bare = !!repo->worktree; >> + if (fspathcmp(gitdir, commondir)) >> + wt->id = xstrdup(find_last_dir_sep(commondir) + 1); > > So here we continue to treat NULL as the main worktree. Okay. > >> + wt->is_current = is_current_worktree(wt); > > Since we're getting the worktree from the repo, shouldn't this be > 'true'?
That's what I thought initially. However is_current_worktree() compares "repo->gitdir" to "the_repository->gitdir" so the "current" worktree is the one that the process was started in, which is not necessarily the same as the one matching "wt->repo->gitdir". It's possible that we will want to change that definition in the future but I opted to make this function consistent with the status quo.
Show 7 quoted lines
>> -/* >> +/* Construct a struct worktree from a struct repository */ >> +struct worktree *get_worktree_from_repository(struct repository *repo); >> + >> + /* > > Nit: extra space?
Good spot I'll fix it
Thanks for the review
Phillip