Commit 4d742d61 authored by Duy Nguyen's avatar Duy Nguyen

path.c: remove the_repo from worktree_git_path() and its callsites

parent db5bbd7e
......@@ -460,7 +460,8 @@ static void print_current_branch_name(void)
static void reject_rebase_or_bisect_branch(const char *target)
{
struct worktree **worktrees = get_worktrees(0);
struct repository *r = the_repository;
struct worktree **worktrees = repo_get_worktrees(r, 0);
int i;
for (i = 0; worktrees[i]; i++) {
......@@ -469,11 +470,12 @@ static void reject_rebase_or_bisect_branch(const char *target)
if (!wt->is_detached)
continue;
if (is_worktree_being_rebased(wt, target))
if (is_worktree_being_rebased(r, wt, target))
die(_("Branch %s is being rebased at %s"),
target, wt->path);
if (is_worktree_being_bisected(wt, target))
if (is_worktree_being_bisected(r, wt, target))
die(_("Branch %s is being bisected at %s"),
target, wt->path);
}
......
......@@ -730,16 +730,17 @@ static void validate_no_submodules(const struct worktree *wt)
struct index_state istate = { NULL };
struct strbuf path = STRBUF_INIT;
int i, found_submodules = 0;
struct repository *r = the_repository;
if (is_directory(worktree_git_path(wt, "modules"))) {
if (is_directory(worktree_git_path(r, wt, "modules"))) {
/*
* There could be false positives, e.g. the "modules"
* directory exists but is empty. But it's a rare case and
* this simpler check is probably good enough for now.
*/
found_submodules = 1;
} else if (read_index_from(&istate, worktree_git_path(wt, "index"),
get_worktree_git_dir(the_repository, wt)) > 0) {
} else if (read_index_from(&istate, worktree_git_path(r, wt, "index"),
get_worktree_git_dir(r, wt)) > 0) {
for (i = 0; i < istate.cache_nr; i++) {
struct cache_entry *ce = istate.cache[i];
int err;
......
......@@ -502,12 +502,14 @@ const char *mkpath(const char *fmt, ...)
return cleanup_path(pathname->buf);
}
const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
const char *worktree_git_path(struct repository *r,
const struct worktree *wt,
const char *fmt, ...)
{
struct strbuf *pathname = get_pathname();
va_list args;
va_start(args, fmt);
do_git_path(the_repository, wt, pathname, fmt, args);
do_git_path(r, wt, pathname, fmt, args);
va_end(args);
return pathname->buf;
}
......
......@@ -1529,15 +1529,16 @@ static void do_add_index_objects_to_pending(struct rev_info *revs,
void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
{
struct repository *r = revs->repo;
struct worktree **worktrees, **p;
repo_read_index(revs->repo);
do_add_index_objects_to_pending(revs, revs->repo->index, flags);
do_add_index_objects_to_pending(revs, r->index, flags);
if (revs->single_worktree)
return;
worktrees = get_worktrees(0);
worktrees = repo_get_worktrees(r, 0);
for (p = worktrees; *p; p++) {
struct worktree *wt = *p;
struct index_state istate = { NULL };
......@@ -1546,8 +1547,8 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
continue; /* current index already taken care of */
if (read_index_from(&istate,
worktree_git_path(wt, "index"),
get_worktree_git_dir(revs->repo, wt)) > 0)
worktree_git_path(r, wt, "index"),
get_worktree_git_dir(r, wt)) > 0)
do_add_index_objects_to_pending(revs, &istate, flags);
discard_index(&istate);
}
......
......@@ -245,7 +245,7 @@ const char *worktree_lock_reason(struct worktree *wt)
if (!wt->lock_reason_valid) {
struct strbuf path = STRBUF_INIT;
strbuf_addstr(&path, worktree_git_path(wt, "locked"));
strbuf_addstr(&path, worktree_git_path(the_repository, wt, "locked"));
if (file_exists(path.buf)) {
struct strbuf lock_reason = STRBUF_INIT;
if (strbuf_read_file(&lock_reason, path.buf, 0) < 0)
......@@ -357,14 +357,15 @@ void update_worktree_location(struct worktree *wt, const char *path_)
strbuf_release(&path);
}
int is_worktree_being_rebased(const struct worktree *wt,
int is_worktree_being_rebased(struct repository *r,
const struct worktree *wt,
const char *target)
{
struct wt_status_state state;
int found_rebase;
memset(&state, 0, sizeof(state));
found_rebase = wt_status_check_rebase(wt, &state) &&
found_rebase = wt_status_check_rebase(r, wt, &state) &&
((state.rebase_in_progress ||
state.rebase_interactive_in_progress) &&
state.branch &&
......@@ -375,14 +376,15 @@ int is_worktree_being_rebased(const struct worktree *wt,
return found_rebase;
}
int is_worktree_being_bisected(const struct worktree *wt,
int is_worktree_being_bisected(struct repository *r,
const struct worktree *wt,
const char *target)
{
struct wt_status_state state;
int found_rebase;
memset(&state, 0, sizeof(state));
found_rebase = wt_status_check_bisect(wt, &state) &&
found_rebase = wt_status_check_bisect(r, wt, &state) &&
state.branch &&
starts_with(target, "refs/heads/") &&
!strcmp(state.branch, target + strlen("refs/heads/"));
......@@ -399,13 +401,14 @@ int is_worktree_being_bisected(const struct worktree *wt,
const struct worktree *find_shared_symref(const char *symref,
const char *target)
{
struct repository *r = the_repository;
const struct worktree *existing = NULL;
static struct worktree **worktrees;
int i = 0;
if (worktrees)
free_worktrees(worktrees);
worktrees = get_worktrees(0);
worktrees = repo_get_worktrees(r, 0);
for (i = 0; worktrees[i]; i++) {
struct worktree *wt = worktrees[i];
......@@ -417,17 +420,17 @@ const struct worktree *find_shared_symref(const char *symref,
continue;
if (wt->is_detached && !strcmp(symref, "HEAD")) {
if (is_worktree_being_rebased(wt, target)) {
if (is_worktree_being_rebased(r, wt, target)) {
existing = wt;
break;
}
if (is_worktree_being_bisected(wt, target)) {
if (is_worktree_being_bisected(r, wt, target)) {
existing = wt;
break;
}
}
refs = get_worktree_ref_store(the_repository, wt);
refs = get_worktree_ref_store(r, wt);
symref_target = refs_resolve_ref_unsafe(refs, symref, 0,
NULL, &flags);
if ((flags & REF_ISSYMREF) &&
......
......@@ -100,16 +100,17 @@ extern const struct worktree *find_shared_symref(const char *symref,
*/
int other_head_refs(each_ref_fn fn, void *cb_data);
int is_worktree_being_rebased(const struct worktree *wt, const char *target);
int is_worktree_being_bisected(const struct worktree *wt, const char *target);
int is_worktree_being_rebased(struct repository *r, const struct worktree *wt, const char *target);
int is_worktree_being_bisected(struct repository *r, const struct worktree *wt, const char *target);
/*
* Similar to git_path() but can produce paths for a specified
* worktree instead of current one
*/
extern const char *worktree_git_path(const struct worktree *wt,
const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
const char *worktree_git_path(struct repository *r,
const struct worktree *wt,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
/*
* Parse a worktree ref (i.e. with prefix main-worktree/ or
......
......@@ -1432,13 +1432,15 @@ static void show_bisect_in_progress(struct wt_status *s,
/*
* Extract branch information from rebase/bisect
*/
static char *get_branch(const struct worktree *wt, const char *path)
static char *get_branch(struct repository *r,
const struct worktree *wt,
const char *path)
{
struct strbuf sb = STRBUF_INIT;
struct object_id oid;
const char *branch_name;
if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
if (strbuf_read_file(&sb, worktree_git_path(r, wt, "%s", path), 0) <= 0)
goto got_nothing;
while (sb.len && sb.buf[sb.len - 1] == '\n')
......@@ -1528,41 +1530,43 @@ static void wt_status_get_detached_from(struct repository *r,
strbuf_release(&cb.buf);
}
int wt_status_check_rebase(const struct worktree *wt,
int wt_status_check_rebase(struct repository *r,
const struct worktree *wt,
struct wt_status_state *state)
{
struct stat st;
if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) {
if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) {
if (!stat(worktree_git_path(r, wt, "rebase-apply"), &st)) {
if (!stat(worktree_git_path(r, wt, "rebase-apply/applying"), &st)) {
state->am_in_progress = 1;
if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size)
if (!stat(worktree_git_path(r, wt, "rebase-apply/patch"), &st) && !st.st_size)
state->am_empty_patch = 1;
} else {
state->rebase_in_progress = 1;
state->branch = get_branch(wt, "rebase-apply/head-name");
state->onto = get_branch(wt, "rebase-apply/onto");
state->branch = get_branch(r, wt, "rebase-apply/head-name");
state->onto = get_branch(r, wt, "rebase-apply/onto");
}
} else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) {
if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st))
} else if (!stat(worktree_git_path(r, wt, "rebase-merge"), &st)) {
if (!stat(worktree_git_path(r, wt, "rebase-merge/interactive"), &st))
state->rebase_interactive_in_progress = 1;
else
state->rebase_in_progress = 1;
state->branch = get_branch(wt, "rebase-merge/head-name");
state->onto = get_branch(wt, "rebase-merge/onto");
state->branch = get_branch(r, wt, "rebase-merge/head-name");
state->onto = get_branch(r, wt, "rebase-merge/onto");
} else
return 0;
return 1;
}
int wt_status_check_bisect(const struct worktree *wt,
int wt_status_check_bisect(struct repository *r,
const struct worktree *wt,
struct wt_status_state *state)
{
struct stat st;
if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) {
if (!stat(worktree_git_path(r, wt, "BISECT_LOG"), &st)) {
state->bisect_in_progress = 1;
state->branch = get_branch(wt, "BISECT_START");
state->branch = get_branch(r, wt, "BISECT_START");
return 1;
}
return 0;
......@@ -1576,16 +1580,16 @@ void wt_status_get_state(struct repository *r,
struct object_id oid;
if (!stat(git_path_merge_head(r), &st)) {
wt_status_check_rebase(NULL, state);
wt_status_check_rebase(r, NULL, state);
state->merge_in_progress = 1;
} else if (wt_status_check_rebase(NULL, state)) {
} else if (wt_status_check_rebase(r, NULL, state)) {
; /* all set */
} else if (!stat(git_path_cherry_pick_head(r), &st) &&
!get_oid("CHERRY_PICK_HEAD", &oid)) {
state->cherry_pick_in_progress = 1;
oidcpy(&state->cherry_pick_head_oid, &oid);
}
wt_status_check_bisect(NULL, state);
wt_status_check_bisect(r, NULL, state);
if (!stat(git_path_revert_head(r), &st) &&
!get_oid("REVERT_HEAD", &oid)) {
state->revert_in_progress = 1;
......
......@@ -137,9 +137,11 @@ void wt_status_collect_free_buffers(struct wt_status *s);
void wt_status_get_state(struct repository *repo,
struct wt_status_state *state,
int get_detached_from);
int wt_status_check_rebase(const struct worktree *wt,
int wt_status_check_rebase(struct repository *r,
const struct worktree *wt,
struct wt_status_state *state);
int wt_status_check_bisect(const struct worktree *wt,
int wt_status_check_bisect(struct repository *r,
const struct worktree *wt,
struct wt_status_state *state);
__attribute__((format (printf, 3, 4)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment