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

[PATCH 2/3] wt-status: add optional stash status information

From
Liam Beguin <liambeguin@gmail.com>
Date
Jun 16, 2017, 04:30 UTC
Message-ID
<20170616043050.29192-3-liambeguin@gmail.com>
In-Reply-To
<20170616043050.29192-1-liambeguin@gmail.com>

Add the `status.showStash` configuration option to allow git-status to show information about currently stashed entries.

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/config.txt |  5 +++++
 wt-status.c              | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 23b807065d92..e83b0f641574 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2992,6 +2992,11 @@ status.displayCommentPrefix::
 	behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
 	Defaults to false.
 
+status.showStash::
+	If set to true, linkgit:git-status[1] will display the number of
+	entries currently stashed away.
+	Defaults to false.
+
 status.showUntrackedFiles::
 	By default, linkgit:git-status[1] and linkgit:git-commit[1] show
 	files which are not currently tracked by Git. Directories which
diff --git a/wt-status.c b/wt-status.c
index bf651f16fae8..7114eec123c8 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -801,6 +801,27 @@ static void wt_longstatus_print_changed(struct wt_status *s)
 	wt_longstatus_print_trailer(s);
 }
 
+static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
+			    const char *email, timestamp_t timestamp, int tz,
+			    const char *message, void *cb_data)
+{
+	int *c = cb_data;
+	(*c)++;
+	return 0;
+}
+
+static void wt_longstatus_print_stash_summary(struct wt_status *s)
+{
+	int stash_count = 0;
+
+	for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
+	if (stash_count > 0)
+		status_printf_ln(s, GIT_COLOR_NORMAL,
+				 Q_("Your stash currently has %d entry",
+				    "Your stash currently has %d entries", stash_count),
+				 stash_count);
+}
+
 static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
 {
 	struct child_process sm_summary = CHILD_PROCESS_INIT;
@@ -1537,6 +1558,7 @@ static void wt_longstatus_print(struct wt_status *s)
 	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
 	const char *branch_status_color = color(WT_STATUS_HEADER, s);
 	struct wt_status_state state;
+	int show_stash = 0;
 
 	memset(&state, 0, sizeof(state));
 	wt_status_get_state(&state,
@@ -1642,6 +1664,8 @@ static void wt_longstatus_print(struct wt_status *s)
 		} else
 			printf(_("nothing to commit, working tree clean\n"));
 	}
+	if (!git_config_get_bool("status.showStash", &show_stash) && show_stash)
+		wt_longstatus_print_stash_summary(s);
 }
 
 static void wt_shortstatus_unmerged(struct string_list_item *it,
-- 
2.9.4
Previous: Junio C HamanoNext: Jeff King
Message 5 of 16 in “add stash count information to git-status command”
  1. 0/3 add stash count information to git-status commandLiam Beguin, Jun 16, 2017
  2. 1/3 stash: update documentation to use 'stash entries'Liam Beguin, Jun 16, 2017
  3. Jeff KingJun 16, 2017
  4. Junio C HamanoJun 16, 2017
  5. 2/3 wt-status: add optional stash status informationLiam Beguin, Jun 16, 2017
  6. Jeff KingJun 16, 2017
  7. Junio C HamanoJun 16, 2017
  8. 3/3 glossary: define stash entriesLiam Beguin, Jun 16, 2017
  9. Jeff KingJun 16, 2017
  10. Jeff KingJun 16, 2017
  11. Liam BeguinJun 16, 2017
  12. 0/3 add stash count information to git-status commandLiam Beguin, Jun 17, 2017
  13. 3/3 glossary: define 'stash entry'Liam Beguin, Jun 17, 2017
  14. 1/3 stash: update documentation to use 'stash entry'Liam Beguin, Jun 17, 2017
  15. 2/3 status: add optional stash count informationLiam Beguin, Jun 17, 2017
  16. Junio C HamanoJun 19, 2017

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.