Re: [PATCH v2 1/2] wt-status: avoid passing NULL worktree
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 25, 2026, 17:11 UTC
- Message-ID
- <xmqqjyw0bve6.fsf@gitster.g>
- In-Reply-To
- <8397f971-39dd-4a18-b520-3157ae15324f@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 38 quoted lines
> On 19/02/2026 20:37, Junio C Hamano wrote: >> Junio C Hamano <gitster@pobox.com> writes: >> >>> In other words, the function is_current_worktree(wt) may not take a >>> repository and always compute things relative to the_repository, but >>> once we wean ourselves off of the_repository, we would/should have >>> repo_is_current_worktree(repo, wt), making is_current_worktree(wt) a >>> thin wrapper for repo_is_current_worktree(the_repository, wt)? >> >> Eh, in light of 2/2 of this series, since wt knows which repository >> it belongs to, what I wrote above does not make much sense. >> Allowing callers to give repo that is different from wt->repo to >> that function is a potential foot-gun. In other words, isn't >> is_current_worktree(wt) using the_worktree and not wt->repo a bug >> already, I have to wonder? > > I wonder that too. You, Karthik and me all initially assumed that the > current worktree would be defined by wt->repo->worktree matching > wt->path (the code actually compares the git_dir of the worktree and the > repository to accommodate bare repositories but the same principle > applies). The use of "the_repository" in is_current_wortree() comes from > replacing get_git_dir() with repo_get_git_dir() in 246deeac951 > (environment: make `get_git_dir()` accept a repository, 2024-09-12). In > get_worktree_git_dir() it comes from replacing git_common_path() with > repo_common_path() in 07242c2a5af (path: drop `git_common_path()` in > favor of `repo_common_path()`, 2025-02-07). I suspect the replacements > were mechanical and not much thought went into considering whether, in a > world where there can be more than one repository per process, they > should use the local repository instance instead of "the_repository". > > The current situation seems counter intuitive and I don't see what the > benefit is in defining the current worktree to be per-process rather > than per-struct-repository instance. > > This series isn't in next yet - shall I re-roll with an extra > preparatory patch changing is_current_worktree() and > git_worktree_git_dir() to use wt->repo, or are you happy to have that as > a separate follow up on top of these patches?
Thanks for investigating how we got here. I do not have strong preference in the order, as long as we eventually get there.