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

[PATCH 2/3] extract setting of wt_status.commitable flag out of wt_status_print_updated()

From
Tay Ray Chuan <rctay89@gmail.com>
Date
Feb 21, 2014, 19:09 UTC
Message-ID
<1393009762-31133-3-git-send-email-rctay89@gmail.com>
In-Reply-To
<1393009762-31133-2-git-send-email-rctay89@gmail.com>

At first glance, wt_status_print_updated() appears to be doing a bunch of printing (as its name implies), and it may not be immediately obvious that it also sets the vital wt_status.commitable flag. Extract this out into a separate function; it is hoped that the improved clarity to future Git contributors would outweigh the performance penalty.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 wt-status.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/wt-status.c b/wt-status.c
index a452407..9b0189c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -589,6 +589,21 @@ void wt_status_collect(struct wt_status *s)
 	wt_status_collect_untracked(s);
 }
 
+void wt_status_mark_commitable(struct wt_status *s)
+{
+	int i;
+
+	for (i = 0; i < s->change.nr; i++) {
+		struct wt_status_change_data *d;
+		d = s->change.items[i].util;
+		if (!d->index_status ||
+		    d->index_status == DIFF_STATUS_UNMERGED)
+			continue;
+		s->commitable = 1;
+		break;
+	}
+}
+
 static void wt_status_print_unmerged(struct wt_status *s)
 {
 	int shown_header = 0;
@@ -627,7 +642,6 @@ static void wt_status_print_updated(struct wt_status *s)
 			continue;
 		if (!shown_header) {
 			wt_status_print_cached_header(s);
-			s->commitable = 1;
 			shown_header = 1;
 		}
 		wt_status_print_change_data(s, WT_STATUS_UPDATED, it);
@@ -1309,6 +1323,7 @@ void wt_status_print(struct wt_status *s)
 		status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
 	}
 
+	wt_status_mark_commitable(s);
 	wt_status_print_updated(s);
 	wt_status_print_unmerged(s);
 	wt_status_print_changed(s);
-- 
1.9.0.291.g027825b
Previous: Tay Ray ChuanNext: Tay Ray Chuan
Message 3 of 8 in “make commit --verbose work with --no-status”
  1. 0/3 make commit --verbose work with --no-statusTay Ray Chuan, Feb 21, 2014
  2. 1/3 rename STATUS_FORMAT_NONE to STATUS_FORMAT_DEFAULTTay Ray Chuan, Feb 21, 2014
  3. 2/3 extract setting of wt_status.commitable flag out of wt_status_print_updated()Tay Ray Chuan, Feb 21, 2014
  4. 3/3 make commit --verbose work with --no-statusTay Ray Chuan, Feb 21, 2014
  5. Jeff KingFeb 22, 2014
  6. Tay Ray ChuanFeb 24, 2014
  7. Jeff KingFeb 24, 2014
  8. Jeff KingFeb 22, 2014

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.