From: Shreyansh Paliwal Date: Fri, 13 Feb 2026 11:59:52 GMT Subject: [RFC][PATCH 0/2] worktree: change representation and usage of primary worktree Message-ID: <20260213120529.15475-1-shreyanshpaliwalcmsmn@gmail.com> While working on reducing global state in wt-status [1], it became clear that some cleanup in the worktree API would be helpful before moving ahead. As of now Primary worktree is represented in three ways, * by passing NULL as a worktree * by a struct worktree whose wt->id is NULL, and * in the ref-store map, by using "/" as the key. This creates ambiguity, callers and helpers often need extra checks for a NULL worktree, and the implicit NULL form makes it harder to rely on fields like wt->repo without falling back to global state. So this patch series involves making the worktree API more robust by removing the usage of NULL as the representation and using wt->id = '/' as the marker for a primary worktree. In patch 1/2, change the internal representation in worktree.c so that the main worktree is identified by '/' instead of NULL. In patch 2/2, update the API usage by modifying callers to obtain the primary worktree via helper and pass an actual struct worktree rather than NULL. I would like to get feedback whether this implementation is in the right direction, and if there is anything else that I should be doing in this cleanup series. [1]- https://lore.kernel.org/git/20260209134439.14492-1-shreyanshpaliwalcmsmn@gmail.com/T/#u Shreyansh Paliwal (2): worktree: represent the primary worktree with "/" instead of NULL worktree: stop passing NULL as primary worktree builtin/fsck.c | 2 +- builtin/worktree.c | 10 +++++++--- path.c | 27 +++++++++++++-------------- path.h | 9 +++------ refs.c | 4 ++-- revision.c | 6 ++++-- worktree.c | 43 +++++++++++++++++++++++++------------------ worktree.h | 7 +++++++ wt-status.c | 22 ++++++++++++---------- 9 files changed, 74 insertions(+), 56 deletions(-) -- 2.53.0