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(), 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shreyansh Paliwal committed
Feb 18, 2026 at 23:23 UTC
4631e22f925fa2af8d8548af97ee2215be101409
1 file changed
+16
-16
wt-status.c
+16
-16
@@ -984,17 +984,17 @@ static int stash_count_refs(const char *refname UNUSED,
984
return 0;
985
}
986
987
-static int count_stash_entries(void)
987
+static int count_stash_entries(struct repository *r)
988
{
989
int n = 0;
990
- refs_for_each_reflog_ent(get_main_ref_store(the_repository),
990
+ refs_for_each_reflog_ent(get_main_ref_store(r),
991
"refs/stash", stash_count_refs, &n);
992
return n;
993
}
994
995
static void wt_longstatus_print_stash_summary(struct wt_status *s)
996
{
997
- int stash_count = count_stash_entries();
997
+ int stash_count = count_stash_entries(s->repo);
998
999
if (stash_count > 0)
1000
status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1287,10 +1287,10 @@ static void show_am_in_progress(struct wt_status *s,
1287
wt_longstatus_print_trailer(s);
1288
}
1289
1290
-static char *read_line_from_git_path(const char *filename)
1290
+static char *read_line_from_git_path(struct repository *r, const char *filename)
1291
{
1292
struct strbuf buf = STRBUF_INIT;
1293
- FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
1293
+ FILE *fp = fopen_or_warn(repo_git_path_append(r, &buf,
1294
"%s", filename), "r");
1295
1296
if (!fp) {
@@ -1325,8 +1325,8 @@ static int split_commit_in_progress(struct wt_status *s)
1325
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
1326
return 0;
1327
1328
- rebase_amend = read_line_from_git_path("rebase-merge/amend");
1329
- rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
1328
+ rebase_amend = read_line_from_git_path(s->repo, "rebase-merge/amend");
1329
+ rebase_orig_head = read_line_from_git_path(s->repo, "rebase-merge/orig-head");
1330
1331
if (!rebase_amend || !rebase_orig_head)
1332
; /* fall through, no split in progress */
@@ -1350,7 +1350,7 @@ static int split_commit_in_progress(struct wt_status *s)
1350
* The function assumes that the line does not contain useless spaces
1351
* before or after the command.
1352
*/
1353
-static void abbrev_oid_in_line(struct strbuf *line)
1353
+static void abbrev_oid_in_line(struct repository *r, struct strbuf *line)
1354
{
1355
struct string_list split = STRING_LIST_INIT_DUP;
1356
struct object_id oid;
@@ -1362,7 +1362,7 @@ static void abbrev_oid_in_line(struct strbuf *line)
1362
return;
1363
1364
if ((2 <= string_list_split(&split, line->buf, " ", 2)) &&
1365
- !repo_get_oid(the_repository, split.items[1].string, &oid)) {
1365
+ !repo_get_oid(r, split.items[1].string, &oid)) {
1366
strbuf_reset(line);
1367
strbuf_addf(line, "%s ", split.items[0].string);
1368
strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV);
@@ -1372,10 +1372,10 @@ static void abbrev_oid_in_line(struct strbuf *line)
1372
string_list_clear(&split, 0);
1373
}
1374
1375
-static int read_rebase_todolist(const char *fname, struct string_list *lines)
1375
+static int read_rebase_todolist(struct repository *r, const char *fname, struct string_list *lines)
1376
{
1377
struct strbuf buf = STRBUF_INIT;
1378
- FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
1378
+ FILE *f = fopen(repo_git_path_append(r, &buf, "%s", fname), "r");
1379
int ret;
1380
1381
if (!f) {
@@ -1384,7 +1384,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
1384
goto out;
1385
}
1386
die_errno("Could not open file %s for reading",
1387
- repo_git_path_replace(the_repository, &buf, "%s", fname));
1387
+ repo_git_path_replace(r, &buf, "%s", fname));
1388
}
1389
while (!strbuf_getline_lf(&buf, f)) {
1390
if (starts_with(buf.buf, comment_line_str))
@@ -1392,7 +1392,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
1392
strbuf_trim(&buf);
1393
if (!buf.len)
1394
continue;
1395
- abbrev_oid_in_line(&buf);
1395
+ abbrev_oid_in_line(r, &buf);
1396
string_list_append(lines, buf.buf);
1397
}
1398
fclose(f);
@@ -1413,8 +1413,8 @@ static void show_rebase_information(struct wt_status *s,
1413
struct string_list have_done = STRING_LIST_INIT_DUP;
1414
struct string_list yet_to_do = STRING_LIST_INIT_DUP;
1415
1416
- read_rebase_todolist("rebase-merge/done", &have_done);
1417
- if (read_rebase_todolist("rebase-merge/git-rebase-todo",
1416
+ read_rebase_todolist(s->repo, "rebase-merge/done", &have_done);
1417
+ if (read_rebase_todolist(s->repo, "rebase-merge/git-rebase-todo",
1418
&yet_to_do))
1419
status_printf_ln(s, color,
1420
_("git-rebase-todo is missing."));
@@ -2259,7 +2259,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
2259
*/
2260
static void wt_porcelain_v2_print_stash(struct wt_status *s)
2261
{
2262
- int stash_count = count_stash_entries();
2262
+ int stash_count = count_stash_entries(s->repo);
2263
char eol = s->null_termination ? '\0' : '\n';
2264
2265
if (stash_count > 0)