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 1/3] wt-status: pass struct repository through function parameters
Date: Wed, 18 Feb 2026 23:23:40 +0530 [thread overview]
Message-ID: <20260218175654.66004-2-shreyanshpaliwalcmsmn@gmail.com> (raw)
In-Reply-To: <20260218175654.66004-1-shreyanshpaliwalcmsmn@gmail.com>
Some functions in wt-status.c (count_stash_entries(),
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 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 | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index e12adb26b9..97c2e10a8c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -984,17 +984,17 @@ static int stash_count_refs(const char *refname UNUSED,
return 0;
}
-static int count_stash_entries(void)
+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;
}
static void wt_longstatus_print_stash_summary(struct wt_status *s)
{
- int stash_count = count_stash_entries();
+ int stash_count = count_stash_entries(s->repo);
if (stash_count > 0)
status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1287,10 +1287,10 @@ static void show_am_in_progress(struct wt_status *s,
wt_longstatus_print_trailer(s);
}
-static char *read_line_from_git_path(const char *filename)
+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) {
@@ -1325,8 +1325,8 @@ static int split_commit_in_progress(struct wt_status *s)
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
return 0;
- rebase_amend = read_line_from_git_path("rebase-merge/amend");
- rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
+ rebase_amend = read_line_from_git_path(s->repo, "rebase-merge/amend");
+ rebase_orig_head = read_line_from_git_path(s->repo, "rebase-merge/orig-head");
if (!rebase_amend || !rebase_orig_head)
; /* fall through, no split in progress */
@@ -1350,7 +1350,7 @@ static int split_commit_in_progress(struct wt_status *s)
* The function assumes that the line does not contain useless spaces
* before or after the command.
*/
-static void abbrev_oid_in_line(struct strbuf *line)
+static void abbrev_oid_in_line(struct repository *r, struct strbuf *line)
{
struct string_list split = STRING_LIST_INIT_DUP;
struct object_id oid;
@@ -1362,7 +1362,7 @@ 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);
@@ -1372,10 +1372,10 @@ static void abbrev_oid_in_line(struct strbuf *line)
string_list_clear(&split, 0);
}
-static int read_rebase_todolist(const char *fname, struct string_list *lines)
+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) {
@@ -1384,7 +1384,7 @@ 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))
@@ -1392,7 +1392,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
strbuf_trim(&buf);
if (!buf.len)
continue;
- abbrev_oid_in_line(&buf);
+ abbrev_oid_in_line(r, &buf);
string_list_append(lines, buf.buf);
}
fclose(f);
@@ -1413,8 +1413,8 @@ static void show_rebase_information(struct wt_status *s,
struct string_list have_done = STRING_LIST_INIT_DUP;
struct string_list yet_to_do = STRING_LIST_INIT_DUP;
- read_rebase_todolist("rebase-merge/done", &have_done);
- if (read_rebase_todolist("rebase-merge/git-rebase-todo",
+ read_rebase_todolist(s->repo, "rebase-merge/done", &have_done);
+ if (read_rebase_todolist(s->repo, "rebase-merge/git-rebase-todo",
&yet_to_do))
status_printf_ln(s, color,
_("git-rebase-todo is missing."));
@@ -2259,7 +2259,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
*/
static void wt_porcelain_v2_print_stash(struct wt_status *s)
{
- int stash_count = count_stash_entries();
+ int stash_count = count_stash_entries(s->repo);
char eol = s->null_termination ? '\0' : '\n';
if (stash_count > 0)
--
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 ` Shreyansh Paliwal [this message]
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=20260218175654.66004-2-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