From: Phillip Wood Date: Wed, 18 Feb 2026 14:19:56 GMT Subject: Re: [PATCH 1/2] wt-status: avoid passing NULL worktree Message-ID: In-Reply-To: On 17/02/2026 17:46, Karthik Nayak wrote: > Phillip Wood writes: >> From: Phillip Wood >> >> 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. >> +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. >> + 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. >> -/* >> +/* 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