Skip to content

Commit 9d0d2ba

Browse files
shreyp135gitster
authored andcommitted
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. 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4631e22 commit 9d0d2ba

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

wt-status.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ void wt_status_prepare(struct repository *r, struct wt_status *s)
150150
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
151151
s->use_color = GIT_COLOR_UNKNOWN;
152152
s->relative_paths = 1;
153-
s->branch = refs_resolve_refdup(get_main_ref_store(the_repository),
153+
s->branch = refs_resolve_refdup(get_main_ref_store(r),
154154
"HEAD", 0, NULL, NULL);
155155
s->reference = "HEAD";
156156
s->fp = stdout;
157-
s->index_file = repo_get_index_file(the_repository);
157+
s->index_file = repo_get_index_file(r);
158158
s->change.strdup_strings = 1;
159159
s->untracked.strdup_strings = 1;
160160
s->ignored.strdup_strings = 1;
@@ -646,7 +646,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
646646

647647
repo_init_revisions(s->repo, &rev, NULL);
648648
memset(&opt, 0, sizeof(opt));
649-
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
649+
opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
650650
setup_revisions(0, NULL, &rev, &opt);
651651

652652
rev.diffopt.flags.override_submodule_config = 1;
@@ -1146,7 +1146,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
11461146
rev.diffopt.ita_invisible_in_index = 1;
11471147

11481148
memset(&opt, 0, sizeof(opt));
1149-
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
1149+
opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
11501150
setup_revisions(0, NULL, &rev, &opt);
11511151

11521152
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
@@ -1317,9 +1317,9 @@ static int split_commit_in_progress(struct wt_status *s)
13171317
!s->branch || strcmp(s->branch, "HEAD"))
13181318
return 0;
13191319

1320-
if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1320+
if (refs_read_ref_full(get_main_ref_store(s->repo), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
13211321
&head_oid, &head_flags) ||
1322-
refs_read_ref_full(get_main_ref_store(the_repository), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1322+
refs_read_ref_full(get_main_ref_store(s->repo), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
13231323
&orig_head_oid, &orig_head_flags))
13241324
return 0;
13251325
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
@@ -1432,7 +1432,7 @@ static void show_rebase_information(struct wt_status *s,
14321432
i++)
14331433
status_printf_ln(s, color, " %s", have_done.items[i].string);
14341434
if (have_done.nr > nr_lines_to_show && s->hints) {
1435-
char *path = repo_git_path(the_repository, "rebase-merge/done");
1435+
char *path = repo_git_path(s->repo, "rebase-merge/done");
14361436
status_printf_ln(s, color,
14371437
_(" (see more in file %s)"), path);
14381438
free(path);
@@ -1534,7 +1534,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
15341534
else
15351535
status_printf_ln(s, color,
15361536
_("You are currently cherry-picking commit %s."),
1537-
repo_find_unique_abbrev(the_repository, &s->state.cherry_pick_head_oid,
1537+
repo_find_unique_abbrev(s->repo, &s->state.cherry_pick_head_oid,
15381538
DEFAULT_ABBREV));
15391539

15401540
if (s->hints) {
@@ -1564,7 +1564,7 @@ static void show_revert_in_progress(struct wt_status *s,
15641564
else
15651565
status_printf_ln(s, color,
15661566
_("You are currently reverting commit %s."),
1567-
repo_find_unique_abbrev(the_repository, &s->state.revert_head_oid,
1567+
repo_find_unique_abbrev(s->repo, &s->state.revert_head_oid,
15681568
DEFAULT_ABBREV));
15691569
if (s->hints) {
15701570
if (has_unmerged(s))
@@ -1691,7 +1691,7 @@ static void wt_status_get_detached_from(struct repository *r,
16911691
char *ref = NULL;
16921692

16931693
strbuf_init(&cb.buf, 0);
1694-
if (refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository), "HEAD", grab_1st_switch, &cb) <= 0) {
1694+
if (refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_1st_switch, &cb) <= 0) {
16951695
strbuf_release(&cb.buf);
16961696
return;
16971697
}
@@ -2099,7 +2099,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
20992099
upstream_is_gone = 1;
21002100
}
21012101

2102-
short_base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2102+
short_base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
21032103
base, 0);
21042104
color_fprintf(s->fp, header_color, "...");
21052105
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)
22332233
ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
22342234
&base, 0, s->ahead_behind_flags);
22352235
if (base) {
2236-
base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2236+
base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
22372237
base, 0);
22382238
fprintf(s->fp, "# branch.upstream %s%c", base, eol);
22392239
free((char *)base);

0 commit comments

Comments
 (0)