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

Re: [PATCH 1/3] wt-status: replace uses of the_repository with local repository instances

From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Date
Feb 2, 2026, 18:57 UTC
Message-ID
<20260202190155.79896-1-shreyanshpaliwalcmsmn@gmail.com>
In-Reply-To
<CAOLa=ZRv4xsy0adY_BcXQkypsgYkLNM6x5LhJGX+B+=aKCwmgg@mail.gmail.com>
Show 8 quoted lines
> > Many instances of the_repository are used in wt-status.c even when a
> > local repository is already available via struct wt_status or struct
> > worktree.
> >
> 
> One missing information is why is it safe to make this change? If is a
> repository field, is it holding the same information, is it always
> defined?

Yes I should have included explanation as well. I have explained below, let me know if this thought process is valid or not.

The replacement of all the_repository with s->repo in this patch are mostly to cases where a repository instance is already available via struct wt_status.

In the current flow, all functions operating on struct wt_status *s are called via commit.c. There, status_init_config() calls wt_status_prepare(), which initializes the struct wt_status and assigns s->repo from the repository instance passed in by the caller. As a result, s->repo is guaranteed to be initialized whenever these functions are invoked.

And commit.c itself still relies on the_repository, within wt-status.c, the local repository pointer refers to the same underlying repository object that the_repository would have pointed to, indirectly until we make commit.c also free of the_repository.

Show 13 quoted lines
> > diff --git a/wt-status.c b/wt-status.c
> > index e12adb26b9..9f4d8fda7f 100644
> > --- a/wt-status.c
> > +++ b/wt-status.c
> > @@ -150,11 +150,11 @@ void wt_status_prepare(struct repository *r, struct wt_status *s)
> >	s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
> >	s->use_color = GIT_COLOR_UNKNOWN;
> >	s->relative_paths = 1;
> > -	s->branch = refs_resolve_refdup(get_main_ref_store(the_repository),
> > +	s->branch = refs_resolve_refdup(get_main_ref_store(s->repo),
> >					"HEAD", 0, NULL, NULL);
> 
> Wouldn't it make more sense to use the function argument 'r' here?

In wt_status_prepare(), s->repo is initialized to r at the top of the function, so both refer to the same repository instance. However, using r directly is more explicit and avoids indirect use. will change this in V2.

Show 11 quoted lines
> > @@ -1723,18 +1723,18 @@ int wt_status_check_rebase(const struct worktree *wt,
> >  {
> >	struct stat st;
> >
> > -	if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) {
> > -		if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) {
> > +	if (!stat(worktree_git_path(wt->repo, wt, "rebase-apply"), &st)) {
> > +		if (!stat(worktree_git_path(wt->repo, wt, "rebase-apply/applying"), &st)) {
> 
> In the same file we make a call 'wt_status_check_rebase(NULL, state)',
> so wouldn't this break?

Yes my bad, it would throw a segfault error. I think the best way to handle this is to explicitly check for the wt to be valid like this,

    if (wt==NULL)
        return 0;

Falling back to the_repository in this case, would probably defeat the purpose.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 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.