diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2016-04-22 20:01:31 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-22 14:09:38 -0700 |
commit | 81eff27b0fb652f80a43bdf18c18cd9bc25840df (patch) | |
tree | 4876f5f723d4dc1e7ce059ba3c9a2b3d5e20dff6 /wt-status.c | |
parent | bcd522a1495146113f8e08e84a6717c04508e197 (diff) | |
download | git-81eff27b0fb652f80a43bdf18c18cd9bc25840df.tar.gz |
wt-status.c: make wt_status_check_rebase() work on any worktree
This is a preparation step for find_shared_symref() to detect if any
worktree is being rebased.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r-- | wt-status.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/wt-status.c b/wt-status.c index ec9240dab7..ce5080c1a2 100644 --- a/wt-status.c +++ b/wt-status.c @@ -15,6 +15,7 @@ #include "column.h" #include "strbuf.h" #include "utf8.h" +#include "worktree.h" static const char cut_line[] = "------------------------ >8 ------------------------\n"; @@ -1262,13 +1263,13 @@ static void show_bisect_in_progress(struct wt_status *s, /* * Extract branch information from rebase/bisect */ -static char *read_and_strip_branch(const char *path) +static char *get_branch(const struct worktree *wt, const char *path) { struct strbuf sb = STRBUF_INIT; unsigned char sha1[20]; const char *branch_name; - if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0) + if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0) goto got_nothing; while (sb.len && sb.buf[sb.len - 1] == '\n') @@ -1295,6 +1296,11 @@ got_nothing: return NULL; } +static char *read_and_strip_branch(const char *path) +{ + return get_branch(NULL, path); +} + struct grab_1st_switch_cbdata { struct strbuf buf; unsigned char nsha1[20]; @@ -1360,27 +1366,28 @@ static void wt_status_get_detached_from(struct wt_status_state *state) strbuf_release(&cb.buf); } -int wt_status_check_rebase(struct wt_status_state *state) +int wt_status_check_rebase(const struct worktree *wt, + struct wt_status_state *state) { struct stat st; - if (!stat(git_path("rebase-apply"), &st)) { - if (!stat(git_path("rebase-apply/applying"), &st)) { + if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) { + if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) { state->am_in_progress = 1; - if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size) + if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size) state->am_empty_patch = 1; } else { state->rebase_in_progress = 1; - state->branch = read_and_strip_branch("rebase-apply/head-name"); - state->onto = read_and_strip_branch("rebase-apply/onto"); + state->branch = get_branch(wt, "rebase-apply/head-name"); + state->onto = get_branch(wt, "rebase-apply/onto"); } - } else if (!stat(git_path("rebase-merge"), &st)) { - if (!stat(git_path("rebase-merge/interactive"), &st)) + } else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) { + if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st)) state->rebase_interactive_in_progress = 1; else state->rebase_in_progress = 1; - state->branch = read_and_strip_branch("rebase-merge/head-name"); - state->onto = read_and_strip_branch("rebase-merge/onto"); + state->branch = get_branch(wt, "rebase-merge/head-name"); + state->onto = get_branch(wt, "rebase-merge/onto"); } else return 0; return 1; @@ -1394,7 +1401,7 @@ void wt_status_get_state(struct wt_status_state *state, if (!stat(git_path_merge_head(), &st)) { state->merge_in_progress = 1; - } else if (wt_status_check_rebase(state)) { + } else if (wt_status_check_rebase(NULL, state)) { ; /* all set */ } else if (!stat(git_path_cherry_pick_head(), &st) && !get_sha1("CHERRY_PICK_HEAD", sha1)) { |