Skip to content

Commit 81eff27

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcd522a commit 81eff27

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

wt-status.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "column.h"
1616
#include "strbuf.h"
1717
#include "utf8.h"
18+
#include "worktree.h"
1819

1920
static const char cut_line[] =
2021
"------------------------ >8 ------------------------\n";
@@ -1262,13 +1263,13 @@ static void show_bisect_in_progress(struct wt_status *s,
12621263
/*
12631264
* Extract branch information from rebase/bisect
12641265
*/
1265-
static char *read_and_strip_branch(const char *path)
1266+
static char *get_branch(const struct worktree *wt, const char *path)
12661267
{
12671268
struct strbuf sb = STRBUF_INIT;
12681269
unsigned char sha1[20];
12691270
const char *branch_name;
12701271

1271-
if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0)
1272+
if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
12721273
goto got_nothing;
12731274

12741275
while (sb.len && sb.buf[sb.len - 1] == '\n')
@@ -1295,6 +1296,11 @@ static char *read_and_strip_branch(const char *path)
12951296
return NULL;
12961297
}
12971298

1299+
static char *read_and_strip_branch(const char *path)
1300+
{
1301+
return get_branch(NULL, path);
1302+
}
1303+
12981304
struct grab_1st_switch_cbdata {
12991305
struct strbuf buf;
13001306
unsigned char nsha1[20];
@@ -1360,27 +1366,28 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
13601366
strbuf_release(&cb.buf);
13611367
}
13621368

1363-
int wt_status_check_rebase(struct wt_status_state *state)
1369+
int wt_status_check_rebase(const struct worktree *wt,
1370+
struct wt_status_state *state)
13641371
{
13651372
struct stat st;
13661373

1367-
if (!stat(git_path("rebase-apply"), &st)) {
1368-
if (!stat(git_path("rebase-apply/applying"), &st)) {
1374+
if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) {
1375+
if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) {
13691376
state->am_in_progress = 1;
1370-
if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size)
1377+
if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size)
13711378
state->am_empty_patch = 1;
13721379
} else {
13731380
state->rebase_in_progress = 1;
1374-
state->branch = read_and_strip_branch("rebase-apply/head-name");
1375-
state->onto = read_and_strip_branch("rebase-apply/onto");
1381+
state->branch = get_branch(wt, "rebase-apply/head-name");
1382+
state->onto = get_branch(wt, "rebase-apply/onto");
13761383
}
1377-
} else if (!stat(git_path("rebase-merge"), &st)) {
1378-
if (!stat(git_path("rebase-merge/interactive"), &st))
1384+
} else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) {
1385+
if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st))
13791386
state->rebase_interactive_in_progress = 1;
13801387
else
13811388
state->rebase_in_progress = 1;
1382-
state->branch = read_and_strip_branch("rebase-merge/head-name");
1383-
state->onto = read_and_strip_branch("rebase-merge/onto");
1389+
state->branch = get_branch(wt, "rebase-merge/head-name");
1390+
state->onto = get_branch(wt, "rebase-merge/onto");
13841391
} else
13851392
return 0;
13861393
return 1;
@@ -1394,7 +1401,7 @@ void wt_status_get_state(struct wt_status_state *state,
13941401

13951402
if (!stat(git_path_merge_head(), &st)) {
13961403
state->merge_in_progress = 1;
1397-
} else if (wt_status_check_rebase(state)) {
1404+
} else if (wt_status_check_rebase(NULL, state)) {
13981405
; /* all set */
13991406
} else if (!stat(git_path_cherry_pick_head(), &st) &&
14001407
!get_sha1("CHERRY_PICK_HEAD", sha1)) {

wt-status.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "color.h"
77
#include "pathspec.h"
88

9+
struct worktree;
10+
911
enum color_wt_status {
1012
WT_STATUS_HEADER = 0,
1113
WT_STATUS_UPDATED,
@@ -100,7 +102,8 @@ void wt_status_prepare(struct wt_status *s);
100102
void wt_status_print(struct wt_status *s);
101103
void wt_status_collect(struct wt_status *s);
102104
void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
103-
int wt_status_check_rebase(struct wt_status_state *state);
105+
int wt_status_check_rebase(const struct worktree *wt,
106+
struct wt_status_state *state);
104107

105108
void wt_shortstatus_print(struct wt_status *s);
106109
void wt_porcelain_print(struct wt_status *s);

0 commit comments

Comments
 (0)