Skip to content

Commit b8ac2bf

Browse files
committed
Merge branch 'sp/wt-status-wo-the-repository'
Reduce dependence on the global the_hash_algo and the_repository variables of wt-status code path. * sp/wt-status-wo-the-repository: wt-status: use hash_algo from local repository instead of global the_hash_algo wt-status: replace uses of the_repository with local repository instances wt-status: pass struct repository through function parameters
2 parents dc6ecd5 + a7cd24d commit b8ac2bf

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

wt-status.c

Lines changed: 31 additions & 31 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;
@@ -670,7 +670,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
670670

671671
repo_init_revisions(s->repo, &rev, NULL);
672672
memset(&opt, 0, sizeof(opt));
673-
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
673+
opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
674674
setup_revisions(0, NULL, &rev, &opt);
675675

676676
rev.diffopt.flags.override_submodule_config = 1;
@@ -1008,17 +1008,17 @@ static int stash_count_refs(const char *refname UNUSED,
10081008
return 0;
10091009
}
10101010

1011-
static int count_stash_entries(void)
1011+
static int count_stash_entries(struct repository *r)
10121012
{
10131013
int n = 0;
1014-
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
1014+
refs_for_each_reflog_ent(get_main_ref_store(r),
10151015
"refs/stash", stash_count_refs, &n);
10161016
return n;
10171017
}
10181018

10191019
static void wt_longstatus_print_stash_summary(struct wt_status *s)
10201020
{
1021-
int stash_count = count_stash_entries();
1021+
int stash_count = count_stash_entries(s->repo);
10221022

10231023
if (stash_count > 0)
10241024
status_printf_ln(s, GIT_COLOR_NORMAL,
@@ -1170,7 +1170,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
11701170
rev.diffopt.ita_invisible_in_index = 1;
11711171

11721172
memset(&opt, 0, sizeof(opt));
1173-
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
1173+
opt.def = s->is_initial ? empty_tree_oid_hex(s->repo->hash_algo) : s->reference;
11741174
setup_revisions(0, NULL, &rev, &opt);
11751175

11761176
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
@@ -1311,10 +1311,10 @@ static void show_am_in_progress(struct wt_status *s,
13111311
wt_longstatus_print_trailer(s);
13121312
}
13131313

1314-
static char *read_line_from_git_path(const char *filename)
1314+
static char *read_line_from_git_path(struct repository *r, const char *filename)
13151315
{
13161316
struct strbuf buf = STRBUF_INIT;
1317-
FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
1317+
FILE *fp = fopen_or_warn(repo_git_path_append(r, &buf,
13181318
"%s", filename), "r");
13191319

13201320
if (!fp) {
@@ -1341,16 +1341,16 @@ static int split_commit_in_progress(struct wt_status *s)
13411341
!s->branch || strcmp(s->branch, "HEAD"))
13421342
return 0;
13431343

1344-
if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1344+
if (refs_read_ref_full(get_main_ref_store(s->repo), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
13451345
&head_oid, &head_flags) ||
1346-
refs_read_ref_full(get_main_ref_store(the_repository), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1346+
refs_read_ref_full(get_main_ref_store(s->repo), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
13471347
&orig_head_oid, &orig_head_flags))
13481348
return 0;
13491349
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
13501350
return 0;
13511351

1352-
rebase_amend = read_line_from_git_path("rebase-merge/amend");
1353-
rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
1352+
rebase_amend = read_line_from_git_path(s->repo, "rebase-merge/amend");
1353+
rebase_orig_head = read_line_from_git_path(s->repo, "rebase-merge/orig-head");
13541354

13551355
if (!rebase_amend || !rebase_orig_head)
13561356
; /* fall through, no split in progress */
@@ -1374,7 +1374,7 @@ static int split_commit_in_progress(struct wt_status *s)
13741374
* The function assumes that the line does not contain useless spaces
13751375
* before or after the command.
13761376
*/
1377-
static void abbrev_oid_in_line(struct strbuf *line)
1377+
static void abbrev_oid_in_line(struct repository *r, struct strbuf *line)
13781378
{
13791379
struct string_list split = STRING_LIST_INIT_DUP;
13801380
struct object_id oid;
@@ -1386,7 +1386,7 @@ static void abbrev_oid_in_line(struct strbuf *line)
13861386
return;
13871387

13881388
if ((2 <= string_list_split(&split, line->buf, " ", 2)) &&
1389-
!repo_get_oid(the_repository, split.items[1].string, &oid)) {
1389+
!repo_get_oid(r, split.items[1].string, &oid)) {
13901390
strbuf_reset(line);
13911391
strbuf_addf(line, "%s ", split.items[0].string);
13921392
strbuf_add_unique_abbrev(line, &oid, DEFAULT_ABBREV);
@@ -1396,10 +1396,10 @@ static void abbrev_oid_in_line(struct strbuf *line)
13961396
string_list_clear(&split, 0);
13971397
}
13981398

1399-
static int read_rebase_todolist(const char *fname, struct string_list *lines)
1399+
static int read_rebase_todolist(struct repository *r, const char *fname, struct string_list *lines)
14001400
{
14011401
struct strbuf buf = STRBUF_INIT;
1402-
FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
1402+
FILE *f = fopen(repo_git_path_append(r, &buf, "%s", fname), "r");
14031403
int ret;
14041404

14051405
if (!f) {
@@ -1408,15 +1408,15 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
14081408
goto out;
14091409
}
14101410
die_errno("Could not open file %s for reading",
1411-
repo_git_path_replace(the_repository, &buf, "%s", fname));
1411+
repo_git_path_replace(r, &buf, "%s", fname));
14121412
}
14131413
while (!strbuf_getline_lf(&buf, f)) {
14141414
if (starts_with(buf.buf, comment_line_str))
14151415
continue;
14161416
strbuf_trim(&buf);
14171417
if (!buf.len)
14181418
continue;
1419-
abbrev_oid_in_line(&buf);
1419+
abbrev_oid_in_line(r, &buf);
14201420
string_list_append(lines, buf.buf);
14211421
}
14221422
fclose(f);
@@ -1437,8 +1437,8 @@ static void show_rebase_information(struct wt_status *s,
14371437
struct string_list have_done = STRING_LIST_INIT_DUP;
14381438
struct string_list yet_to_do = STRING_LIST_INIT_DUP;
14391439

1440-
read_rebase_todolist("rebase-merge/done", &have_done);
1441-
if (read_rebase_todolist("rebase-merge/git-rebase-todo",
1440+
read_rebase_todolist(s->repo, "rebase-merge/done", &have_done);
1441+
if (read_rebase_todolist(s->repo, "rebase-merge/git-rebase-todo",
14421442
&yet_to_do))
14431443
status_printf_ln(s, color,
14441444
_("git-rebase-todo is missing."));
@@ -1456,7 +1456,7 @@ static void show_rebase_information(struct wt_status *s,
14561456
i++)
14571457
status_printf_ln(s, color, " %s", have_done.items[i].string);
14581458
if (have_done.nr > nr_lines_to_show && s->hints) {
1459-
char *path = repo_git_path(the_repository, "rebase-merge/done");
1459+
char *path = repo_git_path(s->repo, "rebase-merge/done");
14601460
status_printf_ln(s, color,
14611461
_(" (see more in file %s)"), path);
14621462
free(path);
@@ -1558,7 +1558,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
15581558
else
15591559
status_printf_ln(s, color,
15601560
_("You are currently cherry-picking commit %s."),
1561-
repo_find_unique_abbrev(the_repository, &s->state.cherry_pick_head_oid,
1561+
repo_find_unique_abbrev(s->repo, &s->state.cherry_pick_head_oid,
15621562
DEFAULT_ABBREV));
15631563

15641564
if (s->hints) {
@@ -1588,7 +1588,7 @@ static void show_revert_in_progress(struct wt_status *s,
15881588
else
15891589
status_printf_ln(s, color,
15901590
_("You are currently reverting commit %s."),
1591-
repo_find_unique_abbrev(the_repository, &s->state.revert_head_oid,
1591+
repo_find_unique_abbrev(s->repo, &s->state.revert_head_oid,
15921592
DEFAULT_ABBREV));
15931593
if (s->hints) {
15941594
if (has_unmerged(s))
@@ -1715,7 +1715,7 @@ static void wt_status_get_detached_from(struct repository *r,
17151715
char *ref = NULL;
17161716

17171717
strbuf_init(&cb.buf, 0);
1718-
if (refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository), "HEAD", grab_1st_switch, &cb) <= 0) {
1718+
if (refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_1st_switch, &cb) <= 0) {
17191719
strbuf_release(&cb.buf);
17201720
return;
17211721
}
@@ -1848,10 +1848,10 @@ void wt_status_get_state(struct repository *r,
18481848
if (!sequencer_get_last_command(r, &action)) {
18491849
if (action == REPLAY_PICK && !state->cherry_pick_in_progress) {
18501850
state->cherry_pick_in_progress = 1;
1851-
oidcpy(&state->cherry_pick_head_oid, null_oid(the_hash_algo));
1851+
oidcpy(&state->cherry_pick_head_oid, null_oid(r->hash_algo));
18521852
} else if (action == REPLAY_REVERT && !state->revert_in_progress) {
18531853
state->revert_in_progress = 1;
1854-
oidcpy(&state->revert_head_oid, null_oid(the_hash_algo));
1854+
oidcpy(&state->revert_head_oid, null_oid(r->hash_algo));
18551855
}
18561856
}
18571857
if (get_detached_from)
@@ -2134,7 +2134,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
21342134
upstream_is_gone = 1;
21352135
}
21362136

2137-
short_base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2137+
short_base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
21382138
base, 0);
21392139
color_fprintf(s->fp, header_color, "...");
21402140
color_fprintf(s->fp, branch_color_remote, "%s", short_base);
@@ -2268,7 +2268,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
22682268
ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
22692269
&base, 0, s->ahead_behind_flags);
22702270
if (base) {
2271-
base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2271+
base = refs_shorten_unambiguous_ref(get_main_ref_store(s->repo),
22722272
base, 0);
22732273
fprintf(s->fp, "# branch.upstream %s%c", base, eol);
22742274
free((char *)base);
@@ -2294,7 +2294,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
22942294
*/
22952295
static void wt_porcelain_v2_print_stash(struct wt_status *s)
22962296
{
2297-
int stash_count = count_stash_entries();
2297+
int stash_count = count_stash_entries(s->repo);
22982298
char eol = s->null_termination ? '\0' : '\n';
22992299

23002300
if (stash_count > 0)
@@ -2665,7 +2665,7 @@ int has_uncommitted_changes(struct repository *r,
26652665
* We have no head (or it's corrupt); use the empty tree,
26662666
* which will complain if the index is non-empty.
26672667
*/
2668-
struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);
2668+
struct tree *tree = lookup_tree(r, r->hash_algo->empty_tree);
26692669
add_pending_object(&rev_info, &tree->object, "");
26702670
}
26712671

0 commit comments

Comments
 (0)