git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2026, 06:08 UTC
Message-ID
<xmqq4inrahti.fsf@gitster.g>
In-Reply-To
<20260208044450.34444-1-shreyanshpaliwalcmsmn@gmail.com>
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
Show 27 quoted lines
>> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
>> 
>> > -int wt_status_check_rebase(const struct worktree *wt,
>> > -			   struct wt_status_state *state)
>> > +int wt_status_check_rebase(struct repository *r,
>> > +	 			const struct worktree *wt,
>> > +			    struct wt_status_state *state)
>> 
>> Funny indentation.
>
> my bad, will fix it.
>
>> 
>> Besides, should we adding a yet another repository parameter to the
>> function?  The worktree wt knows what repository it belongs to.
>> 
>> > -int wt_status_check_bisect(const struct worktree *wt,
>> > +int wt_status_check_bisect(struct repository *r, 
>> > +			   struct worktree *wt,
>> >  			   struct wt_status_state *state)
>> 
>> Same comment about "r" vs "wt->repo" applies here.
>
> Actually adding another repository parameter to both of these functions
> is needed because of the calls like wt_status_check_rebase(NULL, state)
> and wt_status_check_bisect(NULL, state) from wt_status_get_state().
> In the case where wt is NULL, accessing wt->repo can lead to issues.

But stopping thought at that point is not a reasonable thing to do, immediately after you notice that wt is sometimes NULL. It merely means that unconditionally dereferencing wt->repo without thinking is not good enough, doesn't it?

And what is the case where worktree is NULL? What are we doing with worktree set to NULL? Is it when secondary worktrees do not come into the picture at all and you can safely use the_repository?

    ... goes and looks ...

Ahh, I think the real culprit that needs cleaning up is the worktree API, where they pass NULL to mean "the primary worktree that has its .git/ directory at its natural place". So it may not necessarily be the_repository we are dealing with. There is *no* such client code right now, but we could imagine that a program that starts in a repository visits the primary worktree of another repository and asks the worktree status there, and once such a client code appears, we need to be able to say "we are dealing with the primary worktree for this repository".

In the longer run, I think we should fix the worktree API so that even for the primary worktree we will always have a non-NULL "struct worktree" object, perhaps with its .id member set to NULL to signal that it is the primary worktree, so that we do not have to have this strange "we must pass repository redundantly even though we are passing worktree" API elsewhere. Not just this code you are making worse, path.c:worktree_git_path() already is a victim of this misdesign of the worktree API. It has "if wt is given, then the r parameter should be the same as wt->repo" nonsense, which we wouldn't have had to have if we had a worktree object even for the primary worktree, Look at how ugly that code is, and weep X-<.

And the same misdesign of the worktree API has caused your [1/3] to pass 'r' but yet still depend on the_repository, which you had to fix in [2/3], in this function.

So, I dunno. If you are ambitious, you may want to clean up the worktree API before this series. Alternatively you may be able to punt on the parts of the wt-status that interact with worktree API, and move the rest of wt-status less dependent on the_repository, but I am not sure.

Thanks.
Previous: Shreyansh PaliwalNext: Shreyansh Paliwal
Message 48 of 69 in “wt-status: reduce reliance on global state”
  1. 0/3 wt-status: reduce reliance on global stateShreyansh Paliwal, Jan 31, 2026
  2. 1/3 wt-status: replace uses of the_repository with local repository instancesShreyansh Paliwal, Jan 31, 2026
  3. Karthik NayakFeb 2, 2026
  4. Junio C HamanoFeb 2, 2026
  5. Shreyansh PaliwalFeb 2, 2026
  6. Junio C HamanoFeb 2, 2026
  7. Junio C HamanoFeb 2, 2026
  8. Shreyansh PaliwalFeb 3, 2026
  9. Phillip WoodFeb 3, 2026
  10. Shreyansh PaliwalFeb 3, 2026
  11. Phillip WoodFeb 3, 2026
  12. Shreyansh PaliwalFeb 3, 2026
  13. 2/3 wt-status: pass struct repository and wt_status through function parametersShreyansh Paliwal, Jan 31, 2026
  14. 3/3 wt-status: use hash_algo from local repository instead of global the_hash_algoShreyansh Paliwal, Jan 31, 2026
  15. Karthik NayakFeb 2, 2026
  16. Shreyansh PaliwalFeb 2, 2026
  17. Karthik NayakFeb 4, 2026
  18. Shreyansh PaliwalFeb 4, 2026
  19. 0/3 wt-status: reduce reliance on global stateShreyansh Paliwal, Feb 5, 2026
  20. 1/3 wt-status: replace uses of the_repository with local repository instancesShreyansh Paliwal, Feb 5, 2026
  21. Karthik NayakFeb 5, 2026
  22. Karthik NayakFeb 5, 2026
  23. Shreyansh PaliwalFeb 5, 2026
  24. Phillip WoodFeb 5, 2026
  25. Shreyansh PaliwalFeb 5, 2026
  26. 2/3 wt-status: pass struct repository and wt_status through function parametersShreyansh Paliwal, Feb 5, 2026
  27. Karthik NayakFeb 5, 2026
  28. Shreyansh PaliwalFeb 5, 2026
  29. Karthik NayakFeb 6, 2026
  30. Shreyansh PaliwalFeb 6, 2026
  31. Shreyansh PaliwalFeb 6, 2026
  32. Phillip WoodFeb 6, 2026
  33. Shreyansh PaliwalFeb 6, 2026
  34. Phillip WoodFeb 5, 2026
  35. 3/3 wt-status: use hash_algo from local repository instead of global the_hash_algoShreyansh Paliwal, Feb 5, 2026
  36. Shreyansh PaliwalFeb 5, 2026
  37. Phillip WoodFeb 5, 2026
  38. Shreyansh PaliwalFeb 5, 2026
  39. Kristoffer HaugsbakkFeb 5, 2026
  40. Shreyansh PaliwalFeb 5, 2026
  41. 0/3 wt-status: reduce reliance on global stateShreyansh Paliwal, Feb 7, 2026
  42. 1/3 wt-status: pass struct repository through function parametersShreyansh Paliwal, Feb 7, 2026
  43. Junio C HamanoFeb 8, 2026
  44. Shreyansh PaliwalFeb 8, 2026
  45. Karthik NayakFeb 9, 2026
  46. Junio C HamanoFeb 8, 2026
  47. Shreyansh PaliwalFeb 8, 2026
  48. Junio C HamanoFeb 8, 2026
  49. Shreyansh PaliwalFeb 8, 2026
  50. Karthik NayakFeb 9, 2026
  51. Shreyansh PaliwalFeb 9, 2026
  52. Junio C HamanoFeb 9, 2026
  53. Karthik NayakFeb 10, 2026
  54. 2/3 wt-status: replace uses of the_repository with local repository instancesShreyansh Paliwal, Feb 7, 2026
  55. 3/3 wt-status: use hash_algo from local repository instead of global the_hash_algoShreyansh Paliwal, Feb 7, 2026
  56. 0/3 wt-status: reduce reliance on global stateShreyansh Paliwal, Feb 17, 2026
  57. 1/3 wt-status: pass struct repository through function parametersShreyansh Paliwal, Feb 17, 2026
  58. 2/3 wt-status: replace uses of the_repository with local repository instancesShreyansh Paliwal, Feb 17, 2026
  59. 3/3 wt-status: use hash_algo from local repository instead of global the_hash_algoShreyansh Paliwal, Feb 17, 2026
  60. Phillip WoodFeb 18, 2026
  61. Shreyansh PaliwalFeb 18, 2026
  62. 0/3 wt-status: reduce reliance on global stateShreyansh Paliwal, Feb 18, 2026
  63. 1/3 wt-status: pass struct repository through function parametersShreyansh Paliwal, Feb 18, 2026
  64. 2/3 wt-status: replace uses of the_repository with local repository instancesShreyansh Paliwal, Feb 18, 2026
  65. 3/3 wt-status: use hash_algo from local repository instead of global the_hash_algoShreyansh Paliwal, Feb 18, 2026
  66. Junio C HamanoMar 6, 2026
  67. Karthik NayakMar 9, 2026
  68. Junio C HamanoMar 9, 2026
  69. Phillip WoodMar 9, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.