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

Re: [PATCH] builtin-mailinfo.c: Improve the regexp for cleaning up the subject

From
Neil Roberts <bpeeluk@yahoo.co.uk>
Date
Sep 22, 2009, 12:56 UTC
Message-ID
<87pr9juohc.fsf_-_@janet.wally>
In-Reply-To
<87hbuv5km2.fsf@janet.wally>

Previously the regular expression would remove the first set of square brackets regardless of what came before it. If a patch with a summary such as 'Added a[0] to a line' was passed through git-format-patch with the -k option then the summary would be cropped to 'to a line' when applied with git-am.

The new regular expression also matches any number of 're:' prefixes which apparently can be generated by some old mail clients.

The old regexp required that there be at least one set of square
brackets before it would remove the 're:' and this is now fixed.
---
 builtin-mailinfo.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

This patch is meant to apply on top of the two previous patches by Roger Leigh which are available here:

http://marc.info/?l=git&m=124839483217718&w=2 http://marc.info/?l=git&m=124839483317722&w=2

It fixes some small problems as described above.
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 7098c90..f5799f1 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -227,7 +227,7 @@ static void cleanup_subject(struct strbuf *subject)
 	/* Strip off 'Re:' and/or the first text in square brackets, such as
 	   '[PATCH]' at the start of the mail Subject. */
 	status = regcomp(&regex,
-			 "^([Rr]e:)?([^]]*\\[[^]]+\\])(.*)$",
+			 "^([Rr]e:[ \t]*)*(\\[[^]]+\\][ \t]*)?",
 			 REG_EXTENDED);
 
 	if (status) {
@@ -248,10 +248,9 @@ static void cleanup_subject(struct strbuf *subject)
 	/* Store any matches in match. */
 	status = regexec(&regex, subject->buf, 4, match, 0);
 
-	/* If there was a match for \3 in the regex, trim the subject
-	   to this match. */
-	if (!status && match[3].rm_so > 0) {
-		strbuf_remove(subject, 0, match[3].rm_so);
+	/* If there was a match, remove it */
+	if (!status && match[0].rm_so >= 0) {
+		strbuf_remove(subject, 0, match[0].rm_eo);
 		strbuf_trim(subject);
 	}
 
-- 
1.6.0.4
Previous: Neil RobertsNext: Junio C Hamano
Message 12 of 21 in “git mailinfo strips important context from patch subjects”
  1. Roger LeighJun 28, 2009
  2. Jeff KingJun 28, 2009
  3. Junio C HamanoJun 28, 2009
  4. Andreas EricssonJun 29, 2009
  5. mailinfo: Remove only one set of square bracketsAndreas Ericsson, Jun 29, 2009
  6. Junio C HamanoJun 29, 2009
  7. Jeff KingJun 30, 2009
  8. builtin-mailinfo.c: Trim only first pair of square brackets in subjectRoger Leigh, Jun 29, 2009
  9. Jakub NarebskiJun 29, 2009
  10. Roger LeighJun 29, 2009
  11. Neil RobertsSep 22, 2009
  12. Neil RobertsSep 22, 2009
  13. Junio C HamanoSep 22, 2009
  14. Neil RobertsSep 22, 2009
  15. Jason HoldenSep 23, 2009
  16. 2/2 builtin-mailinfo.c: Free regular expression after useRoger Leigh, Jun 29, 2009
  17. Roger LeighJun 29, 2009
  18. git mailinfo strips important context from patch subjectsPaolo Bonzini, Jun 28, 2009
  19. Andreas EricssonJun 29, 2009
  20. Paolo BonziniJun 29, 2009
  21. Andreas EricssonJun 29, 2009

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.