From: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
To: git@vger.kernel.org
Cc: phillip.wood123@gmail.com, gitster@pobox.com,
karthik.188@gmail.com,
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Subject: [PATCH v5 2/3] wt-status: replace uses of the_repository with local repository instances
Date: Wed, 18 Feb 2026 23:23:41 +0530 [thread overview]
Message-ID: <20260218175654.66004-3-shreyanshpaliwalcmsmn@gmail.com> (raw)
In-Reply-To: <20260218175654.66004-1-shreyanshpaliwalcmsmn@gmail.com>
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).
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.
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
wt-status.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 97c2e10a8c..b44b8377e5 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(r),
"HEAD", 0, NULL, NULL);
s->reference = "HEAD";
s->fp = stdout;
- s->index_file = repo_get_index_file(the_repository);
+ s->index_file = repo_get_index_file(r);
s->change.strdup_strings = 1;
s->untracked.strdup_strings = 1;
s->ignored.strdup_strings = 1;
@@ -646,7 +646,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
repo_init_revisions(s->repo, &rev, NULL);
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.flags.override_submodule_config = 1;
@@ -1146,7 +1146,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
rev.diffopt.ita_invisible_in_index = 1;
memset(&opt, 0, sizeof(opt));
- opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
+ opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
@@ -1317,9 +1317,9 @@ static int split_commit_in_progress(struct wt_status *s)
!s->branch || strcmp(s->branch, "HEAD"))
return 0;
- if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
+ if (refs_read_ref_full(get_main_ref_store(s->repo), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
&head_oid, &head_flags) ||
- refs_read_ref_full(get_main_ref_store(the_repository), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
+ refs_read_ref_full(get_main_ref_store(s->repo), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
&orig_head_oid, &orig_head_flags))
return 0;
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
@@ -1432,7 +1432,7 @@ static void show_rebase_information(struct wt_status *s,
i++)
status_printf_ln(s, color, " %s", have_done.items[i].string);
if (have_done.nr > nr_lines_to_show && s->hints) {
- char *path = repo_git_path(the_repository, "rebase-merge/done");
+ char *path = repo_git_path(s->repo, "rebase-merge/done");
status_printf_ln(s, color,
_(" (see more in file %s)"), path);
free(path);
@@ -1534,7 +1534,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently cherry-picking commit %s."),
- repo_find_unique_abbrev(the_repository, &s->state.cherry_pick_head_oid,
+ repo_find_unique_abbrev(s->repo, &s->state.cherry_pick_head_oid,
DEFAULT_ABBREV));
if (s->hints) {
@@ -1564,7 +1564,7 @@ static void show_revert_in_progress(struct wt_status *s,
else
status_printf_ln(s, color,
_("You are currently reverting commit %s."),
- repo_find_unique_abbrev(the_repository, &s->state.revert_head_oid,
+ repo_find_unique_abbrev(s->repo, &s->state.revert_head_oid,
DEFAULT_ABBREV));
if (s->hints) {
if (has_unmerged(s))
@@ -1691,7 +1691,7 @@ static void wt_status_get_detached_from(struct repository *r,
char *ref = NULL;
strbuf_init(&cb.buf, 0);
- if (refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository), "HEAD", grab_1st_switch, &cb) <= 0) {
+ if (refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_1st_switch, &cb) <= 0) {
strbuf_release(&cb.buf);
return;
}
@@ -2099,7 +2099,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
upstream_is_gone = 1;
}
- short_base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+ short_base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
base, 0);
color_fprintf(s->fp, header_color, "...");
color_fprintf(s->fp, branch_color_remote, "%s", short_base);
@@ -2233,7 +2233,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
&base, 0, s->ahead_behind_flags);
if (base) {
- base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+ base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
base, 0);
fprintf(s->fp, "# branch.upstream %s%c", base, eol);
free((char *)base);
--
2.53.0
next prev parent reply other threads:[~2026-02-18 17:57 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
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 ` Shreyansh Paliwal [this message]
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=20260218175654.66004-3-shreyanshpaliwalcmsmn@gmail.com \
--to=shreyanshpaliwalcmsmn@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@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