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

[PATCHv2 2/3] wt-status: More state retrieval abstraction

From
Phil Hord <hordp@cisco.com>
Date
Oct 29, 2012, 23:31 UTC
Message-ID
<1351553513-20385-3-git-send-email-hordp@cisco.com>
In-Reply-To
<1351553513-20385-1-git-send-email-hordp@cisco.com>
wt_status_print_state retrieves some sequencer state
information via wt_status_get_state, but other state
information it deduces on its own.  Replaces these
"local knowledge" deductions with wt_status variables
so we can share more common code in the future.
---
 wt-status.c | 16 +++++++++-------
 wt-status.h |  3 +++
 2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 760f52b..a888120 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -781,7 +781,7 @@ static void show_merge_in_progress(struct wt_status *s,
 				struct wt_status_state *state,
 				const char *color)
 {
-	if (has_unmerged(s)) {
+	if (state->has_unmerged) {
 		status_printf_ln(s, color, _("You have unmerged paths."));
 		if (advice_status_hints)
 			status_printf_ln(s, color,
@@ -867,9 +867,7 @@ static void show_rebase_in_progress(struct wt_status *s,
 				struct wt_status_state *state,
 				const char *color)
 {
-	struct stat st;
-
-	if (has_unmerged(s)) {
+	if (state->has_unmerged) {
 		status_printf_ln(s, color, _("You are currently rebasing."));
 		if (advice_status_hints) {
 			status_printf_ln(s, color,
@@ -879,12 +877,12 @@ static void show_rebase_in_progress(struct wt_status *s,
 			status_printf_ln(s, color,
 				_("  (use \"git rebase --abort\" to check out the original branch)"));
 		}
-	} else if (state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
+	} else if (state->rebase_in_progress || state->commit_is_pending) {
 		status_printf_ln(s, color, _("You are currently rebasing."));
 		if (advice_status_hints)
 			status_printf_ln(s, color,
 				_("  (all conflicts fixed: run \"git rebase --continue\")"));
-	} else if (split_commit_in_progress(s)) {
+	} else if (state->split_in_progress) {
 		status_printf_ln(s, color, _("You are currently splitting a commit during a rebase."));
 		if (advice_status_hints)
 			status_printf_ln(s, color,
@@ -907,7 +905,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
 {
 	status_printf_ln(s, color, _("You are currently cherry-picking."));
 	if (advice_status_hints) {
-		if (has_unmerged(s))
+		if (state->has_unmerged)
 			status_printf_ln(s, color,
 				_("  (fix conflicts and run \"git commit\")"));
 		else
@@ -955,6 +953,10 @@ static void wt_status_get_state(struct wt_status *s , struct wt_status_state *st
 	}
 	if (!stat(git_path("BISECT_LOG"), &st))
 		state->bisect_in_progress = 1;
+
+	state->has_unmerged = has_unmerged(s);
+	state->split_in_progress = split_commit_in_progress(s);
+	state->commit_is_pending = !stat(git_path("MERGE_MSG"), &st);
 }
 
 static void wt_status_print_state(struct wt_status *s)
diff --git a/wt-status.h b/wt-status.h
index 236b41f..0b866a2 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -79,6 +79,9 @@ struct wt_status_state {
 	int rebase_interactive_in_progress;
 	int cherry_pick_in_progress;
 	int bisect_in_progress;
+	int split_in_progress;
+	int has_unmerged;
+	int commit_is_pending;
 };
 
 void wt_status_prepare(struct wt_status *s);
-- 
1.8.0.3.gde9c7d5.dirty
Previous: Phil HordNext: Phil Hord
Message 10 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.