wt-status: split wt_status_state parsing function out
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Wed, 13 Mar 2013 11:42:50 +0000 (18:42 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Mar 2013 05:11:02 +0000 (22:11 -0700)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
wt-status.c
wt-status.h
index aa53436118b6232c56af29c95bcfbfa9427efb54..96b3701b8a5f18086ad1438930d8147d5b13d96f 100644 (file)
@@ -999,40 +999,45 @@ static char *read_and_strip_branch(const char *path)
        return NULL;
 }
 
-static void wt_status_print_state(struct wt_status *s)
+void wt_status_get_state(struct wt_status_state *state)
 {
-       const char *state_color = color(WT_STATUS_HEADER, s);
-       struct wt_status_state state;
        struct stat st;
 
-       memset(&state, 0, sizeof(state));
-
        if (!stat(git_path("MERGE_HEAD"), &st)) {
-               state.merge_in_progress = 1;
+               state->merge_in_progress = 1;
        } else if (!stat(git_path("rebase-apply"), &st)) {
                if (!stat(git_path("rebase-apply/applying"), &st)) {
-                       state.am_in_progress = 1;
+                       state->am_in_progress = 1;
                        if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size)
-                               state.am_empty_patch = 1;
+                               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->rebase_in_progress = 1;
+                       state->branch = read_and_strip_branch("rebase-apply/head-name");
+                       state->onto = read_and_strip_branch("rebase-apply/onto");
                }
        } else if (!stat(git_path("rebase-merge"), &st)) {
                if (!stat(git_path("rebase-merge/interactive"), &st))
-                       state.rebase_interactive_in_progress = 1;
+                       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->rebase_in_progress = 1;
+               state->branch = read_and_strip_branch("rebase-merge/head-name");
+               state->onto = read_and_strip_branch("rebase-merge/onto");
        } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
-               state.cherry_pick_in_progress = 1;
+               state->cherry_pick_in_progress = 1;
        }
        if (!stat(git_path("BISECT_LOG"), &st)) {
-               state.bisect_in_progress = 1;
-               state.branch = read_and_strip_branch("BISECT_START");
+               state->bisect_in_progress = 1;
+               state->branch = read_and_strip_branch("BISECT_START");
        }
+}
+
+static void wt_status_print_state(struct wt_status *s)
+{
+       const char *state_color = color(WT_STATUS_HEADER, s);
+       struct wt_status_state state;
+
+       memset(&state, 0, sizeof(state));
+       wt_status_get_state(&state);
 
        if (state.merge_in_progress)
                show_merge_in_progress(s, &state, state_color);
index b8c351290384ca9e0c52e634ab902abbac861e6d..5ddcbf6b17b5b1d1e60dc562b1fd681bddbb9fde 100644 (file)
@@ -86,6 +86,7 @@ struct wt_status_state {
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
+void wt_status_get_state(struct wt_status_state *state);
 
 void wt_shortstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);