{"thread":{"id":"56755","subject":"[PATCH 0/2] Print stash info in the v2 porcelain format","startedAt":"2021-10-21T22:25:40Z","lastAt":"2021-10-22T01:19:48Z","messageCount":8,"participants":["Øystein Walle","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"439293","messageId":"20211021222532.463375-1-oystwa@gmail.com","threadId":"56755","inReplyTo":null,"subject":"[PATCH 0/2] Print stash info in the v2 porcelain format","fromName":"Øystein Walle","fromEmail":"oystwa@gmail.com","sentAt":"2021-10-21T22:25:30Z","receivedAt":"2021-10-21T22:25:40Z","isPatch":true,"sender":{"key":"oystwa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/794585?v=4"},"body":"When --porcelain=v2 is given --show-stash is silently ignored. But the\nformat is useful for quick gathering of repo status, for e.g. prompts.\nAnd indeed git's own git-prompt.sh supports printing a sigil when stash\nentries exist.\n\nThe first patch is just a very small refactoring. It's far from\nnecessary (although as it stands the second patch depends on it) but it\nmakes sense to me. The second patch is the one that counts.\n\nØystein Walle (2):\n  status: count stash entries in separate function\n  status: print stash info with --porcelain=v2 --show-stash\n\n Documentation/git-status.txt |  8 ++++++++\n t/t7064-wtstatus-pv2.sh      | 15 +++++++++++++++\n wt-status.c                  | 25 +++++++++++++++++++++++--\n 3 files changed, 46 insertions(+), 2 deletions(-)\n\n-- \n2.27.0\n\n"},{"id":"439294","messageId":"20211021222532.463375-2-oystwa@gmail.com","threadId":"56755","inReplyTo":"20211021222532.463375-1-oystwa@gmail.com","subject":"[PATCH 1/2] status: count stash entries in separate function","fromName":"Øystein Walle","fromEmail":"oystwa@gmail.com","sentAt":"2021-10-21T22:25:31Z","receivedAt":"2021-10-21T22:25:47Z","isPatch":true,"sender":{"key":"oystwa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/794585?v=4"},"body":"Make the counting of stash entries contained in one simple function as\nit will be used in the next commit.\n\nSigned-off-by: Øystein Walle <oystwa@gmail.com>\n---\n wt-status.c | 10 ++++++++--\n 1 file changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex e4f29b2b4c..97230477b2 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -948,11 +948,17 @@ static int stash_count_refs(struct object_id *ooid, struct object_id *noid,\n \treturn 0;\n }\n \n+static int count_stash_entries()\n+{\n+\tint n = 0;\n+\tfor_each_reflog_ent(\"refs/stash\", stash_count_refs, &n);\n+\treturn n;\n+}\n+\n static void wt_longstatus_print_stash_summary(struct wt_status *s)\n {\n-\tint stash_count = 0;\n+\tint stash_count = count_stash_entries();\n \n-\tfor_each_reflog_ent(\"refs/stash\", stash_count_refs, &stash_count);\n \tif (stash_count > 0)\n \t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n \t\t\t\t Q_(\"Your stash currently has %d entry\",\n-- \n2.27.0\n\n"},{"id":"439295","messageId":"20211021222532.463375-3-oystwa@gmail.com","threadId":"56755","inReplyTo":"20211021222532.463375-1-oystwa@gmail.com","subject":"[PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash","fromName":"Øystein Walle","fromEmail":"oystwa@gmail.com","sentAt":"2021-10-21T22:25:32Z","receivedAt":"2021-10-21T22:25:48Z","isPatch":true,"sender":{"key":"oystwa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/794585?v=4"},"body":"The v2 porcelain format is very convenient for obtaining a lot of\ninformation about the current state of the repo, but does not contain\nany info about the stash. git status already accepts --show-stash but\nit's silently ignored when --porcelain=v2 is given.\n\nLet's add a simple line to print the number of stash entries but in a\nformat similar in style to the rest of the format.\n\nSigned-off-by: Øystein Walle <oystwa@gmail.com>\n---\n Documentation/git-status.txt |  8 ++++++++\n t/t7064-wtstatus-pv2.sh      | 15 +++++++++++++++\n wt-status.c                  | 15 +++++++++++++++\n 3 files changed, 38 insertions(+)\n\ndiff --git a/Documentation/git-status.txt b/Documentation/git-status.txt\nindex 4a2c3e0408..54a4b29b47 100644\n--- a/Documentation/git-status.txt\n+++ b/Documentation/git-status.txt\n@@ -314,6 +314,14 @@ Line                                     Notes\n ------------------------------------------------------------\n ....\n \n+Stash Information\n+^^^^^^^^^^^^^^^^^\n+\n+If `--show-stash` is given, one line is printed showing the number of stash\n+entries if non-zero:\n+\n+    # stash <N>\n+\n Changed Tracked Entries\n ^^^^^^^^^^^^^^^^^^^^^^^\n \ndiff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh\nindex eeb0534163..47fc21d962 100755\n--- a/t/t7064-wtstatus-pv2.sh\n+++ b/t/t7064-wtstatus-pv2.sh\n@@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'after first commit, stash existing changes' '\n+\tcat >expect <<-EOF &&\n+\t# branch.oid $H0\n+\t# branch.head initial-branch\n+\t# stash 2\n+\tEOF\n+\n+\ttest_when_finished \"git stash pop && git stash pop\" &&\n+\n+\tgit stash -- file_x &&\n+\tgit stash &&\n+\tgit status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'after first commit but omit untracked files and branch' '\n \tcat >expect <<-EOF &&\n \t1 .M N... 100644 100644 100644 $OID_X $OID_X file_x\ndiff --git a/wt-status.c b/wt-status.c\nindex 97230477b2..88c5481e24 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2182,6 +2182,18 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)\n \t}\n }\n \n+/*\n+ * Print the stash count in a porcelain-friendly format\n+ */\n+static void wt_porcelain_v2_print_stash(struct wt_status *s)\n+{\n+\tint stash_count = count_stash_entries();\n+\tchar eol = s->null_termination ? '\\0' : '\\n';\n+\n+\tif (stash_count > 0)\n+\t\tfprintf(s->fp, \"# stash %d%c\", stash_count, eol);\n+}\n+\n /*\n  * Convert various submodule status values into a\n  * fixed-length string of characters in the buffer provided.\n@@ -2443,6 +2455,9 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \tif (s->show_branch)\n \t\twt_porcelain_v2_print_tracking(s);\n \n+\tif (s->show_stash)\n+\t\twt_porcelain_v2_print_stash(s);\n+\n \tfor (i = 0; i < s->change.nr; i++) {\n \t\tit = &(s->change.items[i]);\n \t\td = it->util;\n-- \n2.27.0\n\n"},{"id":"439310","messageId":"xmqq5ytqgd98.fsf@gitster.g","threadId":"56755","inReplyTo":"20211021222532.463375-2-oystwa@gmail.com","subject":"Re: [PATCH 1/2] status: count stash entries in separate function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-10-21T23:38:11Z","receivedAt":"2021-10-21T23:38:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Øystein Walle <oystwa@gmail.com> writes:\n\n> Make the counting of stash entries contained in one simple function as\n> it will be used in the next commit.\n>\n> Signed-off-by: Øystein Walle <oystwa@gmail.com>\n> ---\n>  wt-status.c | 10 ++++++++--\n>  1 file changed, 8 insertions(+), 2 deletions(-)\n>\n> diff --git a/wt-status.c b/wt-status.c\n> index e4f29b2b4c..97230477b2 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> @@ -948,11 +948,17 @@ static int stash_count_refs(struct object_id *ooid, struct object_id *noid,\n>  \treturn 0;\n>  }\n>  \n> +static int count_stash_entries()\n\nProbably \"static int count_stash_entries(void)\" was what was meant\nhere.\n\n> +{\n> +\tint n = 0;\n\nHave a blank line between the block of decls at the beginning of the\nfunction and the first statement.\n\n> +\tfor_each_reflog_ent(\"refs/stash\", stash_count_refs, &n);\n> +\treturn n;\n> +}\n\nI briefly wondered if this want to be size_t or some other unsigned\nintegral type, but this is merely refactoring the existing code, so\nit is not just OK but is correct to use the same \"int\" as before.\n\n>  static void wt_longstatus_print_stash_summary(struct wt_status *s)\n>  {\n> -\tint stash_count = 0;\n> +\tint stash_count = count_stash_entries();\n>  \n> -\tfor_each_reflog_ent(\"refs/stash\", stash_count_refs, &stash_count);\n>  \tif (stash_count > 0)\n>  \t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n>  \t\t\t\t Q_(\"Your stash currently has %d entry\",\n\nOK.\n"},{"id":"439311","messageId":"xmqq1r4egct2.fsf@gitster.g","threadId":"56755","inReplyTo":"20211021222532.463375-3-oystwa@gmail.com","subject":"Re: [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-10-21T23:47:53Z","receivedAt":"2021-10-21T23:47:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Øystein Walle <oystwa@gmail.com> writes:\n\n> The v2 porcelain format is very convenient for obtaining a lot of\n> information about the current state of the repo, but does not contain\n> any info about the stash. git status already accepts --show-stash but\n> it's silently ignored when --porcelain=v2 is given.\n>\n> Let's add a simple line to print the number of stash entries but in a\n> format similar in style to the rest of the format.\n\nWho is the primary target audience of this feature?  IDEs that read\nfrom \"git status --porcelain\"?\n\nWhoever it is, if they bothered enough to pass an extra option\n(i.e. \"--show-stash\") to their \"git status\" invocation, I wonder if\nthey want to know at least what \"git stash list\" would give you at\nthe same time.  After all, the --porcelain output is all about\nmachine readability and reducing the number of forks would be what\nthose people would be interested in, wouldn't it?  I dunno.\n\nThanks.\n\n"},{"id":"439315","messageId":"CAPig+cQQurJuKieFcnZ8_10CaJA7vZ2kV=S+AaHVX3nhsVUG-Q@mail.gmail.com","threadId":"56755","inReplyTo":"20211021222532.463375-3-oystwa@gmail.com","subject":"Re: [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-10-22T00:05:53Z","receivedAt":"2021-10-22T00:06:06Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Oct 21, 2021 at 6:25 PM Øystein Walle <oystwa@gmail.com> wrote:\n> The v2 porcelain format is very convenient for obtaining a lot of\n> information about the current state of the repo, but does not contain\n> any info about the stash. git status already accepts --show-stash but\n> it's silently ignored when --porcelain=v2 is given.\n>\n> Let's add a simple line to print the number of stash entries but in a\n> format similar in style to the rest of the format.\n>\n> Signed-off-by: Øystein Walle <oystwa@gmail.com>\n> ---\n> diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh\n> @@ -113,6 +113,21 @@ test_expect_success 'after first commit, create unstaged changes' '\n> +test_expect_success 'after first commit, stash existing changes' '\n> +       cat >expect <<-EOF &&\n> +       # branch.oid $H0\n> +       # branch.head initial-branch\n> +       # stash 2\n> +       EOF\n> +\n> +       test_when_finished \"git stash pop && git stash pop\" &&\n\nIf it's indeed important to clean up the stashes when the test\nfinishes, then the test_when_finished() invocation should probably be\na bit more robust...\n\n> +       git stash -- file_x &&\n> +       git stash &&\n\n... since, as it is now, if an error occurs between these two\ngit-stash invocations or before them, then there will only be zero or\none stashes, so the double stash-pop by test_when_finished() will\nitself errout out. Better, perhaps to do this:\n\n    test_when_finished \"git stash pop && git stash pop || :\" &&\n\n> +       git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&\n> +       test_cmp expect actual\n> +'\n"},{"id":"439320","messageId":"xmqq4k99gava.fsf@gitster.g","threadId":"56755","inReplyTo":"CAPig+cQQurJuKieFcnZ8_10CaJA7vZ2kV=S+AaHVX3nhsVUG-Q@mail.gmail.com","subject":"Re: [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-10-22T00:29:45Z","receivedAt":"2021-10-22T00:29:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n>> +       test_when_finished \"git stash pop && git stash pop\" &&\n>\n> If it's indeed important to clean up the stashes when the test\n> finishes, then the test_when_finished() invocation should probably be\n> a bit more robust...\n>\n>> +       git stash -- file_x &&\n>> +       git stash &&\n>\n> ... since, as it is now, if an error occurs between these two\n> git-stash invocations or before them, then there will only be zero or\n> one stashes, so the double stash-pop by test_when_finished() will\n> itself errout out. Better, perhaps to do this:\n>\n>     test_when_finished \"git stash pop && git stash pop || :\" &&\n>\n>> +       git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&\n>> +       test_cmp expect actual\n>> +'\n\nThere is no \"I do not care what is in the stash right now, just\nclear all\"?\n"},{"id":"439322","messageId":"CAPig+cTMC0ZAkdzwQ6qu9ra0bjBGDP5wtsqccnbFq+0cdTRiSw@mail.gmail.com","threadId":"56755","inReplyTo":"xmqq4k99gava.fsf@gitster.g","subject":"Re: [PATCH 2/2] status: print stash info with --porcelain=v2 --show-stash","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-10-22T01:19:34Z","receivedAt":"2021-10-22T01:19:48Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Oct 21, 2021 at 8:30 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> >> +       test_when_finished \"git stash pop && git stash pop\" &&\n> >\n> > If it's indeed important to clean up the stashes when the test\n> > finishes, then the test_when_finished() invocation should probably be\n> > a bit more robust...\n> >\n> >> +       git stash -- file_x &&\n> >> +       git stash &&\n> >\n> > ... since, as it is now, if an error occurs between these two\n> > git-stash invocations or before them, then there will only be zero or\n> > one stashes, so the double stash-pop by test_when_finished() will\n> > itself errout out. Better, perhaps to do this:\n> >\n> >     test_when_finished \"git stash pop && git stash pop || :\" &&\n>\n> There is no \"I do not care what is in the stash right now, just\n> clear all\"?\n\nIndeed, I wondered that too but was too lazy to look and I had\nforgotten about `git stash clear`, which makes this much simpler:\n\n    test_when_finished \"git stash clear\" &&\n"}]}