aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-16 10:48:13 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-16 10:48:14 -0700
commitb8ac2bf3f092454e00a325dfd280f56f0a8f0f15 (patch)
treec31f82c1720781a94ed0062db3ffc9c61b00c2ed
parentdc6ecd5354dca88d51b6d6562777fc8fc10d77e1 (diff)
parenta7cd24de0b3b679c16ae3ee8215af06aeea1e6a3 (diff)
downloadgit-b8ac2bf3f092454e00a325dfd280f56f0a8f0f15.tar.xz
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
-rw-r--r--wt-status.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/wt-status.c b/wt-status.c
index 543000311f..479ccc3304 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;
@@ -670,7 +670,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;
@@ -1008,17 +1008,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,
@@ -1170,7 +1170,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;
@@ -1311,10 +1311,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) {
@@ -1341,16 +1341,16 @@ 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)
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 */
@@ -1374,7 +1374,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;
@@ -1386,7 +1386,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);
@@ -1396,10 +1396,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) {
@@ -1408,7 +1408,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))
@@ -1416,7 +1416,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);
@@ -1437,8 +1437,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."));
@@ -1456,7 +1456,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);
@@ -1558,7 +1558,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) {
@@ -1588,7 +1588,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))
@@ -1715,7 +1715,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;
}
@@ -1848,10 +1848,10 @@ void wt_status_get_state(struct repository *r,
if (!sequencer_get_last_command(r, &action)) {
if (action == REPLAY_PICK && !state->cherry_pick_in_progress) {
state->cherry_pick_in_progress = 1;
- oidcpy(&state->cherry_pick_head_oid, null_oid(the_hash_algo));
+ oidcpy(&state->cherry_pick_head_oid, null_oid(r->hash_algo));
} else if (action == REPLAY_REVERT && !state->revert_in_progress) {
state->revert_in_progress = 1;
- oidcpy(&state->revert_head_oid, null_oid(the_hash_algo));
+ oidcpy(&state->revert_head_oid, null_oid(r->hash_algo));
}
}
if (get_detached_from)
@@ -2134,7 +2134,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);
@@ -2268,7 +2268,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);
@@ -2294,7 +2294,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)
@@ -2665,7 +2665,7 @@ int has_uncommitted_changes(struct repository *r,
* We have no head (or it's corrupt); use the empty tree,
* which will complain if the index is non-empty.
*/
- struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);
+ struct tree *tree = lookup_tree(r, r->hash_algo->empty_tree);
add_pending_object(&rev_info, &tree->object, "");
}