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

[PATCH 3/3] mailinfo: with -b, keep space after [foo]

From
Thomas Rast <trast@student.ethz.ch>
Date
Jan 11, 2012, 20:13 UTC
Message-ID
<673657ccd5577ef5c2b6be2c7d0039218c31596d.1326312730.git.trast@student.ethz.ch>
In-Reply-To
<e915a551c9bbf12f4d8fd929e9ed24f3223790ee.1326312730.git.trast@student.ethz.ch>

The logic for the -b mode, where [PATCH] is dropped but [foo] is not, silently ate all spaces after the ].

Fix this by keeping the next isspace() character, if there is any. Being more thorough is pointless, as the later cleanup_space() call will normalize any sequence of whitespace to a single ' '.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 builtin/mailinfo.c |   11 ++++++++++-
 t/t4150-am.sh      |    2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index bfb32b7..eaf9e15 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -250,8 +250,17 @@ static void cleanup_subject(struct strbuf *subject)
 			    (7 <= remove &&
 			     memmem(subject->buf + at, remove, "PATCH", 5)))
 				strbuf_remove(subject, at, remove);
-			else
+			else {
 				at += remove;
+				/*
+				 * If the input had a space after the ], keep
+				 * it.  We don't bother with finding the end of
+				 * the space, since we later normalize it
+				 * anyway.
+				 */
+				if (isspace(subject->buf[at]))
+					at += 1;
+			}
 			continue;
 		}
 		break;
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 7e7c83c..8807b60 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -262,7 +262,7 @@ test_expect_success 'am --keep really keeps the subject' '
 	grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
 '
 
-test_expect_failure 'am --keep-non-patch really keeps the non-patch part' '
+test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
 	rm -fr .git/rebase-apply &&
 	git reset --hard &&
 	git checkout HEAD^ &&
-- 
1.7.9.rc0.168.g3847c
Previous: Thomas Rast
Message 9 of 9 in “mailinfo documentation: accurately describe non -k case”
  1. 1/3 mailinfo documentation: accurately describe non -k caseThomas Rast, Jan 11, 2012
  2. 2/3 am: learn passing -b to mailinfoThomas Rast, Jan 11, 2012
  3. Junio C HamanoJan 12, 2012
  4. Thomas RastJan 12, 2012
  5. 1/2 am: learn passing -b to mailinfoThomas Rast, Jan 16, 2012
  6. 2/2 mailinfo: with -b, keep space after [foo]Thomas Rast, Jan 16, 2012
  7. Junio C HamanoJan 19, 2012
  8. Thomas RastJan 20, 2012
  9. 3/3 mailinfo: with -b, keep space after [foo]Thomas Rast, Jan 11, 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.