Re: [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters
- From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
- Date
- Feb 9, 2026, 13:43 UTC
- Message-ID
- <20260209134439.14492-1-shreyanshpaliwalcmsmn@gmail.com>
- In-Reply-To
- <CAOLa=ZRaWA14sootWSPo5g4Yi4GBXf6HjdkdBY1Tt_+V0szCjg@mail.gmail.com>
[...]
Show 40 quoted lines
> > Thank you very much for the detailed explanation and for pointing towards > > the bigger picture. > > > > From what I have understood, the worktree being NULL refers to the > > primary worktree (as it does not indicate which repository so it means in > > respect to the_repository). So if we want to access the primary worktree > > of a specific repository or even the local repository, NULL does not carry > > enough information. > > And obviously, using NULL as primary worktree introduces extra checks and > > measures as we saw in the previous discussion. > > > > I would be very interested (and the more logical step) to fixing worktree api > > first, and then revisiting the wt-status series on top of that, once the API > > makes it possible to rely on wt->repo without the NULL risks. > > > > So a possible in the worktree api cleanup approach could be, > > > > * Make primary worktree as an instance of struct worktree but seperate > > it by having a marker like id = NULL. > > > > I would like to point out that we already have a function which provides > a main worktree, see both `get_main_worktree()` & `is_main_worktree()`. > In short, a worktree with id = NULL seems to be treated as the main > worktree. > > The harder part would be correcting all code where `struct worktree *` > is passed and has special meaning for NULL vs non-NULL. See > `strbuf_worktree_gitdir()` which also distinguishes between `wt == > NULL`, `wt->id == NULL` and `wt->id != NULL`. > > So cleanup would require identifying all such spots and fixing them too. > > > * Add this primary worktree in the struct repository (e.g. repo->primary_wt). > > > > This also is tricky. We currently already store all worktrees in the > repository in `struct strmap worktree_ref_stores`. Here, for the main > worktree we use '\' (see `get_worktree_ref_store()`). So perhaps we > should formalize using `\` for the main worktree everywhere.
Thanks for these points, I definitely need a better understanding of the whole worktree api usage and flow before anything further. So I am going to spend some time on it. Once I have a clearer picture, I will send a seperate rfc attempt on this cleanup and we can discuss it further there.
Best, Shreyansh