git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Øystein Walle" <oystwa@gmail.com>
To: git@vger.kernel.org
Cc: "Øystein Walle" <oystwa@gmail.com>
Subject: [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash
Date: Fri, 22 Oct 2021 00:25:32 +0200	[thread overview]
Message-ID: <20211021222532.463375-3-oystwa@gmail.com> (raw)
In-Reply-To: <20211021222532.463375-1-oystwa@gmail.com>

The v2 porcelain format is very convenient for obtaining a lot of
information about the current state of the repo, but does not contain
any info about the stash. git status already accepts --show-stash but
it's silently ignored when --porcelain=v2 is given.

Let's add a simple line to print the number of stash entries but in a
format similar in style to the rest of the format.

Signed-off-by: Øystein Walle <oystwa@gmail.com>
---
 Documentation/git-status.txt |  8 ++++++++
 t/t7064-wtstatus-pv2.sh      | 15 +++++++++++++++
 wt-status.c                  | 15 +++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 4a2c3e0408..54a4b29b47 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -314,6 +314,14 @@ Line                                     Notes
 ------------------------------------------------------------
 ....
 
+Stash Information
+^^^^^^^^^^^^^^^^^
+
+If `--show-stash` is given, one line is printed showing the number of stash
+entries if non-zero:
+
+    # stash <N>
+
 Changed Tracked Entries
 ^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index eeb0534163..47fc21d962 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '
 	test_cmp expect actual
 '
 
+test_expect_success 'after first commit, stash existing changes' '
+	cat >expect <<-EOF &&
+	# branch.oid $H0
+	# branch.head initial-branch
+	# stash 2
+	EOF
+
+	test_when_finished "git stash pop && git stash pop" &&
+
+	git stash -- file_x &&
+	git stash &&
+	git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'after first commit but omit untracked files and branch' '
 	cat >expect <<-EOF &&
 	1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
diff --git a/wt-status.c b/wt-status.c
index 97230477b2..88c5481e24 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -2182,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 	}
 }
 
+/*
+ * Print the stash count in a porcelain-friendly format
+ */
+static void wt_porcelain_v2_print_stash(struct wt_status *s)
+{
+	int stash_count = count_stash_entries();
+	char eol = s->null_termination ? '\0' : '\n';
+
+	if (stash_count > 0)
+		fprintf(s->fp, "# stash %d%c", stash_count, eol);
+}
+
 /*
  * Convert various submodule status values into a
  * fixed-length string of characters in the buffer provided.
@@ -2443,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)
 	if (s->show_branch)
 		wt_porcelain_v2_print_tracking(s);
 
+	if (s->show_stash)
+		wt_porcelain_v2_print_stash(s);
+
 	for (i = 0; i < s->change.nr; i++) {
 		it = &(s->change.items[i]);
 		d = it->util;
-- 
2.27.0


  parent reply	other threads:[~2021-10-21 22:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 22:25 [PATCH 0/2] Print stash info in the v2 porcelain format Øystein Walle
2021-10-21 22:25 ` [PATCH 1/2] status: count stash entries in separate function Øystein Walle
2021-10-21 23:38   ` Junio C Hamano
2021-10-21 22:25 ` Øystein Walle [this message]
2021-10-21 23:47   ` [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash Junio C Hamano
2021-10-22  0:05   ` Eric Sunshine
2021-10-22  0:29     ` Junio C Hamano
2021-10-22  1:19       ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211021222532.463375-3-oystwa@gmail.com \
    --to=oystwa@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).