From mboxrd@z Thu Jan 1 00:00:00 1970 From: Neil Roberts Subject: Re: [PATCH] builtin-mailinfo.c: Improve the regexp for cleaning up the subject Date: Tue, 22 Sep 2009 13:56:47 +0100 Message-ID: <87pr9juohc.fsf_-_@janet.wally> References: <7vfxdkez96.fsf@alter.siamese.dyndns.org> <1246310220-16909-1-git-send-email-rleigh@debian.org> <87hbuv5km2.fsf@janet.wally> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Sep 22 14:57:03 2009 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mq4vQ-0005gp-Bt for gcvg-git-2@lo.gmane.org; Tue, 22 Sep 2009 14:56:56 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756448AbZIVM4q (ORCPT ); Tue, 22 Sep 2009 08:56:46 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756398AbZIVM4p (ORCPT ); Tue, 22 Sep 2009 08:56:45 -0400 Received: from smtpout.karoo.kcom.com ([212.50.160.34]:4539 "EHLO smtpout.karoo.kcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756350AbZIVM4p (ORCPT ); Tue, 22 Sep 2009 08:56:45 -0400 X-IronPort-AV: E=Sophos;i="4.44,431,1249254000"; d="scan'208";a="134265036" Received: from unknown (HELO localhost) ([91.84.60.59]) by smtpout.karoo.kcom.com with ESMTP; 22 Sep 2009 13:56:47 +0100 In-Reply-To: <87hbuv5km2.fsf@janet.wally> (Neil Roberts's message of "Tue, 22 Sep 2009 11:39:33 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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(®ex, - "^([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(®ex, 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