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

[PATCH v5 0/3] wt-status: reduce reliance on global state

From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Date
Feb 18, 2026, 17:53 UTC
Message-ID
<20260218175654.66004-1-shreyanshpaliwalcmsmn@gmail.com>
In-Reply-To
<20260131190106.389289-1-shreyanshpaliwalcmsmn@gmail.com>

In wt-status.c code still relies on some global variables, including the_repository and the_hash_algo, even in cases where a repository instance is already available via struct wt_status or struct repository.

In patch 1/3, update function parameters and callers to pass and use struct repository instead of the_repository where no local repository access was available.

In patch 2/3, replace direct uses of the_repository with repository instances already available in local structs.

In patch 3/3, replace remaining uses of the global the_hash_algo with the hash algorithm stored in the respective repository instance.

These changes remove uses of the_repository and the_hash_algo from wt-status.c and reduce its dependence on global state.

The 'USE_THE_REPOSITORY_VARIABLE' macro cannot yet be removed, since these patches only eliminate some uses of the_repository and the_hash_algo, while some global variables are still referenced.

In particular wt-status.c still relies on the following globals,
* the_repository, this is still used in functions like worktree_git_path()
  and wt_status_check_bisect/rebase() which are dependant on the worktree
  API and they are being handled in a seperate patch series[1].
* core_apply_sparse_checkout, this is already being addressed in an ongoing
  patch series [2].
* comment_line_str and DEFAULT_ABBREV, these both still are used in
  wt-status.c but they dont have any equivalent local instances.

[1]- https://lore.kernel.org/git/20260213120529.15475-1-shreyanshpaliwalcmsmn@gmail.com/T/#mf664ad751faaf2eaca138302b1cc9d3856c9fec3 [2]- https://lore.kernel.org/git/5e56e1cc4172cfff9e917a068184e102aa70bf1d.1769256839.git.belkid98@gmail.com/t/#u

Shreyansh Paliwal (3):
  wt-status: pass struct repository through function parameters
  wt-status: replace uses of the_repository with local repository
    instances
  wt-status: use hash_algo from local repository instead of global
    the_hash_algo
 wt-status.c | 62 ++++++++++++++++++++++++++---------------------------
 1 file changed, 31 insertions(+), 31 deletions(-)
---
Changes in v5:
 - Added the usage of struct repository *r in addition to adding it as a parameter to the functions,
    in patch 1/3 instead of doing that in 2/3.
Range-diff against v4:
1:  a3683a5e17 ! 1:  620cf8832b wt-status: pass struct repository through function parameters
    @@ Commit message
         wt-status: pass struct repository through function parameters
         Some functions in wt-status.c (count_stash_entries(),
    -    read_line_from_git_path(), abbrev_oid_in_line(), read_rebase_todolist())
    -    do not have access to a local repository instance and rely on the_repository.
    +    read_line_from_git_path(), abbrev_oid_in_line(), and
    +    read_rebase_todolist()) rely on the_repository as they do not have access
    +    to a local repository instance.
    -    Add a struct repository *r parameter to these functions, and pass the local
    -    repository through the callers where already they can access a local repository
    -    instance either directly by struct repository *r or
    -    by struct wt_state *s (s->repo).
    +    Add a struct repository *r parameter to these functions and pass the local
    +    repository instance through the callers, which already have access to it
    +    either directly by struct repository *r or indirectly by struct wt_state
    +    *s (s->repo).
    +
    +    Replace uses of the_repository in these functions with the passed parameter.
         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
    @@ wt-status.c: static int stash_count_refs(const char *refname UNUSED,
     +static int count_stash_entries(struct repository *r)
      {
      	int n = 0;
    - 	refs_for_each_reflog_ent(get_main_ref_store(the_repository),
    -@@ wt-status.c: static int count_stash_entries(void)
    +-	refs_for_each_reflog_ent(get_main_ref_store(the_repository),
    ++	refs_for_each_reflog_ent(get_main_ref_store(r),
    + 				 "refs/stash", stash_count_refs, &n);
    + 	return n;
    + }
      static void wt_longstatus_print_stash_summary(struct wt_status *s)
      {
    @@ wt-status.c: static void show_am_in_progress(struct wt_status *s,
     +static char *read_line_from_git_path(struct repository *r, const char *filename)
      {
      	struct strbuf buf = STRBUF_INIT;
    - 	FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
    +-	FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
    ++	FILE *fp = fopen_or_warn(repo_git_path_append(r, &buf,
    + 						      "%s", filename), "r");
    +
    + 	if (!fp) {
     @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
      	if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
      		return 0;
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
      {
      	struct string_list split = STRING_LIST_INIT_DUP;
      	struct object_id oid;
    +@@ wt-status.c: static void abbrev_oid_in_line(struct strbuf *line)
    + 		return;
    +
    + 	if ((2 <= string_list_split(&split, line->buf, " ", 2)) &&
    +-	    !repo_get_oid(the_repository, split.items[1].string, &oid)) {
    ++	    !repo_get_oid(r, split.items[1].string, &oid)) {
    + 		strbuf_reset(line);
    + 		strbuf_addf(line, "%s ", split.items[0].string);
    + 		strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV);
     @@ wt-status.c: static void abbrev_oid_in_line(struct strbuf *line)
      	string_list_clear(&split, 0);
      }
    @@ wt-status.c: static void abbrev_oid_in_line(struct strbuf *line)
     +static int read_rebase_todolist(struct repository *r, const char *fname, struct string_list *lines)
      {
      	struct strbuf buf = STRBUF_INIT;
    - 	FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
    +-	FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
    ++	FILE *f = fopen(repo_git_path_append(r, &buf, "%s", fname), "r");
    + 	int ret;
    +
    + 	if (!f) {
    +@@ wt-status.c: static int read_rebase_todolist(const char *fname, struct string_list *lines)
    + 			goto out;
    + 		}
    + 		die_errno("Could not open file %s for reading",
    +-			  repo_git_path_replace(the_repository, &buf, "%s", fname));
    ++			  repo_git_path_replace(r, &buf, "%s", fname));
    + 	}
    + 	while (!strbuf_getline_lf(&buf, f)) {
    + 		if (starts_with(buf.buf, comment_line_str))
     @@ wt-status.c: static int read_rebase_todolist(const char *fname, struct string_list *lines)
      		strbuf_trim(&buf);
      		if (!buf.len)
2:  f3b4c3e972 ! 2:  13e0c5bcd7 wt-status: replace uses of the_repository with local repository instances
    @@ Metadata
      ## Commit message ##
         wt-status: replace uses of the_repository with local repository instances
    -    wt-status.c uses the global the_repository in several places even when
    -    a repository instance is already available via struct wt_status *s or
    -    struct repository *r.
    +    wt-status.c uses the global the_repository in several places even when a
    +    repository instance is already available via struct wt_status *s or struct
    +    repository *r.
    -    Replace these uses of the_repository with the repository available
    -    in the local context (i.e. s->repo or r).
    +    Replace these uses of the_repository with the repository available in the
    +    local context (i.e. s->repo or r).
    -    The replacements of all the_repository with s->repo are mostly
    -    to cases where a repository instance is already available via
    -    struct wt_status *s and struct repository *r, all functions operating on
    -    struct wt_status *s are only used after s is initialized by wt_status_prepare(),
    -    which sets s->repo from the repository provided by the caller.
    -    As a result, s->repo is guaranteed to be available and consistent whenever
    -    these functions are invoked.
    +    The replacements of all the_repository with s->repo are mostly to cases
    +    where a repository instance is already available via struct wt_status *s
    +    and struct repository *r, all functions operating on struct wt_status *s
    +    are only used after s is initialized by wt_status_prepare(), which sets
    +    s->repo from the repository provided by the caller. As a result, s->repo is
    +    guaranteed to be available and consistent whenever these functions are
    +    invoked.
         This reduces reliance on global state and keeps wt-status consistent,
    -    though many functions operating on struct wt_status *s
    -    are called via commit.c and it still relies on the_repository,
    -    but within wt-status.c the local repository pointer
    -    refers to the same underlying repository object.
    +    though many functions operating on struct wt_status *s are called via
    +    commit.c and it still relies on the_repository, but within wt-status.c the
    +    local repository pointer refers to the same underlying repository object.
         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
    @@ wt-status.c: static void wt_status_collect_changes_index(struct wt_status *s)
      	setup_revisions(0, NULL, &rev, &opt);
      	rev.diffopt.flags.override_submodule_config = 1;
    -@@ wt-status.c: static int stash_count_refs(const char *refname UNUSED,
    - static int count_stash_entries(struct repository *r)
    - {
    - 	int n = 0;
    --	refs_for_each_reflog_ent(get_main_ref_store(the_repository),
    -+	refs_for_each_reflog_ent(get_main_ref_store(r),
    - 				 "refs/stash", stash_count_refs, &n);
    - 	return n;
    - }
     @@ wt-status.c: static void wt_longstatus_print_verbose(struct wt_status *s)
      	rev.diffopt.ita_invisible_in_index = 1;
    @@ wt-status.c: static void wt_longstatus_print_verbose(struct wt_status *s)
      	setup_revisions(0, NULL, &rev, &opt);
      	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
    -@@ wt-status.c: static void show_am_in_progress(struct wt_status *s,
    - static char *read_line_from_git_path(struct repository *r, const char *filename)
    - {
    - 	struct strbuf buf = STRBUF_INIT;
    --	FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
    -+	FILE *fp = fopen_or_warn(repo_git_path_append(r, &buf,
    - 						      "%s", filename), "r");
    -
    - 	if (!fp) {
     @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
      	    !s->branch || strcmp(s->branch, "HEAD"))
      		return 0;
    @@ wt-status.c: static int split_commit_in_progress(struct wt_status *s)
      			       &orig_head_oid, &orig_head_flags))
      		return 0;
      	if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
    -@@ wt-status.c: static void abbrev_oid_in_line(struct repository *r, struct strbuf *line)
    - 		return;
    -
    - 	if ((2 <= string_list_split(&split, line->buf, " ", 2)) &&
    --	    !repo_get_oid(the_repository, split.items[1].string, &oid)) {
    -+	    !repo_get_oid(r, split.items[1].string, &oid)) {
    - 		strbuf_reset(line);
    - 		strbuf_addf(line, "%s ", split.items[0].string);
    - 		strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV);
    -@@ wt-status.c: static void abbrev_oid_in_line(struct repository *r, struct strbuf *line)
    - static int read_rebase_todolist(struct repository *r, const char *fname, struct string_list *lines)
    - {
    - 	struct strbuf buf = STRBUF_INIT;
    --	FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
    -+	FILE *f = fopen(repo_git_path_append(r, &buf, "%s", fname), "r");
    - 	int ret;
    -
    - 	if (!f) {
    -@@ wt-status.c: static int read_rebase_todolist(struct repository *r, const char *fname, struct
    - 			goto out;
    - 		}
    - 		die_errno("Could not open file %s for reading",
    --			  repo_git_path_replace(the_repository, &buf, "%s", fname));
    -+			  repo_git_path_replace(r, &buf, "%s", fname));
    - 	}
    - 	while (!strbuf_getline_lf(&buf, f)) {
    - 		if (starts_with(buf.buf, comment_line_str))
     @@ wt-status.c: static void show_rebase_information(struct wt_status *s,
      				i++)
      				status_printf_ln(s, color, "   %s", have_done.items[i].string);
3:  7efaf6b3fb = 3:  2bf22dd925 wt-status: use hash_algo from local repository instead of global the_hash_algo
--
2.53.0
Previous: Shreyansh PaliwalNext: Shreyansh Paliwal
Message 62 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.