Re: [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters
- From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
- Date
- Feb 6, 2026, 09:32 UTC
- Message-ID
- <20260206093257.1178858-1-shreyanshpaliwalcmsmn@gmail.com>
- In-Reply-To
- <CAOLa=ZR21J6sPDh0cUgzv+td70Mwck1-Ev-43OtZ7mYBX17z5A@mail.gmail.com>
Show 38 quoted lines
> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes: > > >> > Some functions in wt-status.c relied on the_repository because no > >> > repository instance was available in their local scope. > >> > There is also a specific case in wt_status_check_rebase() where the > >> > worktree can be NULL, so accessing wt->repo may lead to a segfault. > >> > > >> > Update these functions to accept a struct repository or struct > >> > wt_status parameter, and adjust callers accordingly. Replace the > >> > remaining uses of the_repository in these functions with the > >> > passed-in repository instance. > >> > > >> > This removes the use of the_repository global variable from > >> > wt-status.c completely. > >> > > >> > >> Okay, but this doesn't fix the issue I stated in the previous commit. I > >> do wonder if we can re-order the commits and pass the repo struct to > >> functions like 'get_branch()'. > > > > Sorry, I didn’t fully think through what you were pointing out in the > > previous version. I initially assumed you were only referring to the > > specific call involving wt_status_check_rebase(NULL, state). > > > > So struct worktree *wt is not guaranteed to be defined and can be > > NULL. Because of that, relying on wt->repo is unsafe. > > Instead, rather than depending on the worktree for repository access (wt->repo), > > we can pass struct repository explicitly through the relevant call > > stack, like in functions get_branch() and wt_status_check_bisect(). > > I hope I have understood it correctly. > > > > Best, > > Shreyansh > > I would say its not that black and white. There's a lot of context > around it. There are places where `struct worktree *wt` should > definitely be defined. So we have to take it on a case by case basis. > Which is what makes these refactors a bit tricky.
But lets say if we do pass struct repository explicitly wherever it is doubtful, rather than relying on worktree, does it have any downside ?