From: Phillip Wood <phillip.wood123@gmail.com>
To: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>, git@vger.kernel.org
Cc: gitster@pobox.com, karthik.188@gmail.com
Subject: Re: [PATCH V2 0/3] wt-status: reduce reliance on global state
Date: Thu, 5 Feb 2026 15:53:08 +0000 [thread overview]
Message-ID: <16274976-17c0-499b-8225-de2d783ed343@gmail.com> (raw)
In-Reply-To: <20260205102815.134373-1-shreyanshpaliwalcmsmn@gmail.com>
On 05/02/2026 10:27, Shreyansh Paliwal wrote:
> I forgot to include the changes in the version.
>
> Changes in V2,
> - Explained the changes and the reason more elaborately in commit message.
> - Passed struct repository instead of accessing struct worktree in
> wt_status_check_rebase() and shifted this change to patch 2/3 instead of 1/3.
> - Added information about leftover globals in the cover.
As well as describing the changes it is very helpful to include a range-diff to
show what's changed - see the --range-diff option to "git format-patch". I've
pasted the range-diff between V1 and V2 below
Thanks
Phillip
1: 1bf5449c7a8 ! 1: 7285c64e672 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
- 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.
-
- Replace direct uses of the global the_repository with the repository
- instance carried by the local structs (e.g. s->repo, wt->repo).
-
- This helps reduce reliance on global repository state.
+ wt-status.c uses the global the_repository in several places even when
+ a repository instance is already available via struct wt_status or
+ struct worktree.
+
+ Replace these direct uses of the_repository with the repository carried
+ by the local structs (e.g. s->repo, wt->repo).
+
+ The replacements of all the_repository with s->repo are mostly
+ to cases where a repository instance is already available via
+ struct wt_status. 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.
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
@@ wt-status.c: void wt_status_prepare(struct repository *r, struct wt_status *s)
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),
++ s->branch = refs_resolve_refdup(get_main_ref_store(r),
"HEAD", 0, NULL, NULL);
s->reference = "HEAD";
s->fp = stdout;
@@ wt-status.c: static void wt_status_get_detached_from(struct repository *r,
strbuf_release(&cb.buf);
return;
}
-@@ wt-status.c: 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)) {
- state->am_in_progress = 1;
-- if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size)
-+ if (!stat(worktree_git_path(wt->repo, wt, "rebase-apply/patch"), &st) && !st.st_size)
- state->am_empty_patch = 1;
- } else {
- state->rebase_in_progress = 1;
- state->branch = get_branch(wt, "rebase-apply/head-name");
- state->onto = get_branch(wt, "rebase-apply/onto");
- }
-- } else if (!stat(worktree_git_path(the_repository, wt, "rebase-merge"), &st)) {
-- if (!stat(worktree_git_path(the_repository, wt, "rebase-merge/interactive"), &st))
-+ } else if (!stat(worktree_git_path(wt->repo, wt, "rebase-merge"), &st)) {
-+ if (!stat(worktree_git_path(wt->repo, wt, "rebase-merge/interactive"), &st))
- state->rebase_interactive_in_progress = 1;
- else
- state->rebase_in_progress = 1;
@@ wt-status.c: int wt_status_check_bisect(const struct worktree *wt,
{
struct stat st;
2: 8a0b489c3be ! 2: 0a04c957f12 wt-status: pass struct repository and wt_status through function parameters
@@ Commit message
Some functions in wt-status.c relied on the_repository because no
repository instance was available in their local scope.
-
- Update these functions to accept struct repository or struct
- wt_status as parameters, and adjust callers accordingly.
-
- Replace remaining uses of the_repository in these functions with the
+ 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 completely removes the use of the_repository global variable
- in wt-status.c.
+ This removes the use of the_repository global variable from
+ wt-status.c completely.
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
+ ## branch.c ##
+@@ branch.c: static void prepare_checked_out_branches(void)
+ free(old);
+ }
+
+- if (wt_status_check_rebase(wt, &state) &&
++ if (wt_status_check_rebase(wt->repo, wt, &state) &&
+ (state.rebase_in_progress || state.rebase_interactive_in_progress) &&
+ state.branch) {
+ struct strbuf ref = STRBUF_INIT;
+
+ ## worktree.c ##
+@@ worktree.c: int is_worktree_being_rebased(const struct worktree *wt,
+ int found_rebase;
+
+ memset(&state, 0, sizeof(state));
+- found_rebase = wt_status_check_rebase(wt, &state) &&
++ found_rebase = wt_status_check_rebase(wt->repo, wt, &state) &&
+ (state.rebase_in_progress ||
+ state.rebase_interactive_in_progress) &&
+ state.branch &&
+
## wt-status.c ##
@@ wt-status.c: static int stash_count_refs(const char *refname UNUSED,
return 0;
@@ wt-status.c: static void show_rebase_information(struct wt_status *s,
&yet_to_do))
status_printf_ln(s, color,
_("git-rebase-todo is missing."));
+@@ wt-status.c: static void wt_status_get_detached_from(struct repository *r,
+ strbuf_release(&cb.buf);
+ }
+
+-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)
+ {
+ 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(r, wt, "rebase-apply"), &st)) {
++ if (!stat(worktree_git_path(r, wt, "rebase-apply/applying"), &st)) {
+ state->am_in_progress = 1;
+- if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size)
++ if (!stat(worktree_git_path(r, wt, "rebase-apply/patch"), &st) && !st.st_size)
+ state->am_empty_patch = 1;
+ } else {
+ state->rebase_in_progress = 1;
+ state->branch = get_branch(wt, "rebase-apply/head-name");
+ state->onto = get_branch(wt, "rebase-apply/onto");
+ }
+- } else if (!stat(worktree_git_path(the_repository, wt, "rebase-merge"), &st)) {
+- if (!stat(worktree_git_path(the_repository, wt, "rebase-merge/interactive"), &st))
++ } else if (!stat(worktree_git_path(r, wt, "rebase-merge"), &st)) {
++ if (!stat(worktree_git_path(r, wt, "rebase-merge/interactive"), &st))
+ state->rebase_interactive_in_progress = 1;
+ else
+ state->rebase_in_progress = 1;
+@@ wt-status.c: void wt_status_get_state(struct repository *r,
+ enum replay_action action;
+
+ if (!stat(git_path_merge_head(r), &st)) {
+- wt_status_check_rebase(NULL, state);
++ wt_status_check_rebase(r, NULL, state);
+ state->merge_in_progress = 1;
+- } else if (wt_status_check_rebase(NULL, state)) {
++ } else if (wt_status_check_rebase(r, NULL, state)) {
+ ; /* all set */
+ } else if (refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
+ !repo_get_oid(r, "CHERRY_PICK_HEAD", &oid)) {
@@ wt-status.c: static void wt_porcelain_v2_print_tracking(struct wt_status *s)
*/
static void wt_porcelain_v2_print_stash(struct wt_status *s)
@@ wt-status.c: static void wt_porcelain_v2_print_tracking(struct wt_status *s)
char eol = s->null_termination ? '\0' : '\n';
if (stash_count > 0)
+
+ ## wt-status.h ##
+@@ wt-status.h: void wt_status_state_free_buffers(struct wt_status_state *s);
+ void wt_status_get_state(struct repository *repo,
+ struct wt_status_state *state,
+ int get_detached_from);
+-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);
+ int wt_status_check_bisect(const struct worktree *wt,
+ struct wt_status_state *state);
+
3: e2cf365bad5 ! 3: 74b28d95299 wt-status: use hash_algo from local repository instead of global the_hash_algo
@@ Metadata
## Commit message ##
wt-status: use hash_algo from local repository instead of global the_hash_algo
- wt-status.c uses the global the_hash_algo even though a repository
- instance is already available via struct repository *r.
+ wt-status.c still uses the global the_hash_algo even though a repository
+ instance is already available via struct wt_status.
Replace uses of the_hash_algo with the hash algorithm stored in the
- associated repository (r->hash_algo).
+ associated repository (s->repo->hash_algo or r->hash_algo).
This removes another dependency on global state and keeps wt-status
consistent with local repository usage.
next prev parent reply other threads:[~2026-02-05 15:53 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 18:57 [PATCH 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 1/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-02 10:02 ` Karthik Nayak
2026-02-02 18:42 ` Junio C Hamano
2026-02-02 18:57 ` Shreyansh Paliwal
2026-02-02 22:41 ` Junio C Hamano
2026-02-02 23:03 ` Junio C Hamano
2026-02-03 9:53 ` Shreyansh Paliwal
2026-02-03 11:06 ` Phillip Wood
2026-02-03 15:20 ` Shreyansh Paliwal
2026-02-03 10:58 ` Phillip Wood
2026-02-03 15:15 ` Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 2/3] wt-status: pass struct repository and wt_status through function parameters Shreyansh Paliwal
2026-01-31 18:57 ` [PATCH 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-02 10:03 ` Karthik Nayak
2026-02-02 19:03 ` Shreyansh Paliwal
2026-02-04 10:18 ` Karthik Nayak
2026-02-04 11:22 ` Shreyansh Paliwal
2026-02-05 10:13 ` [PATCH V2 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-05 10:13 ` [PATCH V2 1/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-05 10:59 ` Karthik Nayak
2026-02-05 11:11 ` Karthik Nayak
2026-02-05 12:18 ` Shreyansh Paliwal
2026-02-05 16:08 ` Phillip Wood
2026-02-05 17:41 ` Shreyansh Paliwal
2026-02-05 10:13 ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status through function parameters Shreyansh Paliwal
2026-02-05 11:09 ` Karthik Nayak
2026-02-05 12:04 ` Shreyansh Paliwal
2026-02-06 9:24 ` Karthik Nayak
2026-02-06 9:32 ` Shreyansh Paliwal
2026-02-06 12:57 ` Shreyansh Paliwal
2026-02-06 14:54 ` Phillip Wood
2026-02-06 17:06 ` Shreyansh Paliwal
2026-02-05 15:58 ` Phillip Wood
2026-02-05 10:13 ` [PATCH V2 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-05 10:27 ` [PATCH V2 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-05 15:53 ` Phillip Wood [this message]
2026-02-05 17:39 ` Shreyansh Paliwal
2026-02-05 18:02 ` Kristoffer Haugsbakk
2026-02-05 18:18 ` Shreyansh Paliwal
2026-02-07 10:00 ` [PATCH v3 " Shreyansh Paliwal
2026-02-07 10:00 ` [PATCH v3 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-08 1:14 ` Junio C Hamano
2026-02-08 4:55 ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status " Shreyansh Paliwal
2026-02-09 8:36 ` [PATCH v3 1/3] wt-status: pass struct repository " Karthik Nayak
2026-02-08 1:21 ` Junio C Hamano
2026-02-08 4:44 ` [PATCH V2 2/3] wt-status: pass struct repository and wt_status " Shreyansh Paliwal
2026-02-08 6:08 ` Junio C Hamano
2026-02-08 15:25 ` Shreyansh Paliwal
2026-02-09 9:02 ` Karthik Nayak
2026-02-09 13:43 ` Shreyansh Paliwal
2026-02-09 16:13 ` Junio C Hamano
2026-02-10 9:50 ` Karthik Nayak
2026-02-07 10:00 ` [PATCH v3 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-07 10:00 ` [PATCH v3 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-17 17:29 ` [PATCH v4 0/3] wt-status: reduce reliance on global state Shreyansh Paliwal
2026-02-17 17:29 ` [PATCH v4 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-17 17:29 ` [PATCH v4 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-17 17:29 ` [PATCH v4 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-02-18 16:13 ` [PATCH v4 0/3] wt-status: reduce reliance on global state Phillip Wood
2026-02-18 16:48 ` Shreyansh Paliwal
2026-02-18 17:53 ` [PATCH v5 " Shreyansh Paliwal
2026-02-18 17:53 ` [PATCH v5 1/3] wt-status: pass struct repository through function parameters Shreyansh Paliwal
2026-02-18 17:53 ` [PATCH v5 2/3] wt-status: replace uses of the_repository with local repository instances Shreyansh Paliwal
2026-02-18 17:53 ` [PATCH v5 3/3] wt-status: use hash_algo from local repository instead of global the_hash_algo Shreyansh Paliwal
2026-03-06 22:31 ` [PATCH v5 0/3] wt-status: reduce reliance on global state Junio C Hamano
2026-03-09 10:32 ` Karthik Nayak
2026-03-09 18:30 ` Junio C Hamano
2026-03-09 10:35 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16274976-17c0-499b-8225-de2d783ed343@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=shreyanshpaliwalcmsmn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox