git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv3 1/4] Refactor print_state into get_state

From
Phil Hord <hordp@cisco.com>
Date
Nov 9, 2012, 18:56 UTC
Message-ID
<1352487385-5929-2-git-send-email-hordp@cisco.com>
In-Reply-To
<1352487385-5929-1-git-send-email-hordp@cisco.com>

Recently git-status learned to display the state of the git sequencer in long form to help the user remember an interrupted command. This information is useful to other callers who do not want it printed in the same way.

Split the new print_state function into separate get_state and print_state functions so others can get this state info and share common code.

Signed-off-by: Phil Hord <hordp@cisco.com>
---
 wt-status.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 2a9658b..760f52b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -928,34 +928,41 @@ static void show_bisect_in_progress(struct wt_status *s,
 	wt_status_print_trailer(s);
 }
 
-static void wt_status_print_state(struct wt_status *s)
+static void wt_status_get_state(struct wt_status *s , 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));
+	memset(state, 0, sizeof(*state));
 
+	/* Determine sequencer activity */
 	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->rebase_in_progress = 1;
 		}
 	} 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->rebase_in_progress = 1;
 	} 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->bisect_in_progress = 1;
+}
+
+static void wt_status_print_state(struct wt_status *s)
+{
+	const char *state_color = color(WT_STATUS_HEADER, s);
+	struct wt_status_state state;
+
+	wt_status_get_state(s, &state);
 
 	if (state.merge_in_progress)
 		show_merge_in_progress(s, &state, state_color);
-- 
1.8.0.3.gde9c7d5.dirty
Previous: Phil HordNext: Ramkumar Ramachandra
Message 13 of 26 in “[PATCHv2] git-status: show short sequencer state”
  1. Phil HordOct 23, 2012
  2. Phil HordOct 23, 2012
  3. Jeff KingOct 25, 2012
  4. Phil HordOct 25, 2012
  5. Phil HordOct 29, 2012
  6. Jeff KingOct 29, 2012
  7. Phil HordOct 29, 2012
  8. 0/3 git-status short sequencer state infoPhil Hord, Oct 29, 2012
  9. 1/3 Refactor print_state into get_statePhil Hord, Oct 29, 2012
  10. 2/3 wt-status: More state retrieval abstractionPhil Hord, Oct 29, 2012
  11. 3/3 git-status: show short sequencer statePhil Hord, Oct 29, 2012
  12. 0/4 git-status short sequencer state infoPhil Hord, Nov 9, 2012
  13. 1/4 Refactor print_state into get_statePhil Hord, Nov 9, 2012
  14. Ramkumar RamachandraNov 12, 2012
  15. 2/4 wt-status: Teach sequencer advice to use get_statePhil Hord, Nov 9, 2012
  16. 3/4 git-status: show short sequencer statePhil Hord, Nov 9, 2012
  17. Junio C HamanoNov 12, 2012
  18. Phil HordNov 12, 2012
  19. Phil HordNov 13, 2012
  20. Junio C HamanoNov 14, 2012
  21. Phil HordNov 14, 2012
  22. Junio C HamanoNov 14, 2012
  23. Phil HordNov 14, 2012
  24. Junio C HamanoNov 14, 2012
  25. Junio C HamanoNov 14, 2012
  26. 4/4 Add tests for git-status --sequencerPhil Hord, Nov 9, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.