From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: [PATCH] git-format-patch, git-send-email: generate/handle escaped >From Date: Thu, 11 Jun 2009 12:00:34 +0200 Message-ID: <1244714434-20794-1-git-send-email-bonzini@gnu.org> To: X-From: git-owner@vger.kernel.org Thu Jun 11 12:02:08 2009 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1MEh6l-0000YR-CQ for gcvg-git-2@gmane.org; Thu, 11 Jun 2009 12:02:07 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762076AbZFKKAs (ORCPT ); Thu, 11 Jun 2009 06:00:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1762031AbZFKKAr (ORCPT ); Thu, 11 Jun 2009 06:00:47 -0400 Received: from fencepost.gnu.org ([140.186.70.10]:41871 "EHLO fencepost.gnu.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761868AbZFKKAq (ORCPT ); Thu, 11 Jun 2009 06:00:46 -0400 Received: from bonzini by fencepost.gnu.org with local (Exim 4.67) (envelope-from ) id 1MEh5T-0007wm-MC for git@vger.kernel.org; Thu, 11 Jun 2009 06:00:47 -0400 X-Mailer: git-send-email 1.6.0.3 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: I noticed that the mbox files generated by git-format-patch (especially with --stdout) are not proper in the sense that the lines starting with "From " are not escaped with a > sign. This is unlikely to cause problems with mail clients such as mutt, but many scripts designed to work on mbox files will fumble in this case. This patch fixes it and dually unescapes the lines in git-send-email. Signed-off-by: Paolo Bonzini --- git-send-email.perl | 1 + pretty.c | 2 ++ t/t4014-format-patch.sh | 13 +++++++++++++ t/t9001-send-email.sh | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 0 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 4c795a4..de57303 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1085,6 +1085,7 @@ foreach my $t (@files) { } # Now parse the message body while() { + s/^>From /From /; $message .= $_; if (/^(Signed-off-by|Cc): (.*)$/i) { chomp; diff --git a/pretty.c b/pretty.c index e5328da..d7f8228 100644 --- a/pretty.c +++ b/pretty.c @@ -868,6 +868,8 @@ void pp_remainder(enum cmit_fmt fmt, memset(sb->buf + sb->len, ' ', indent); strbuf_setlen(sb, sb->len + indent); } + if (fmt == CMIT_FMT_EMAIL && !prefixcmp(line, "From ")) + strbuf_addch(sb, '>'); strbuf_add(sb, line, linelen); strbuf_addch(sb, '\n'); } diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 922a894..8474718 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -28,6 +28,13 @@ test_expect_success setup ' git update-index file && git commit -m "Side changes #3 with \\n backslash-n in it." && + git checkout -b more && + for i in A B C; do echo "$i"; done >>file && + git update-index file && + git commit -m "More changes + +From this point on..." && + git checkout master && git diff-tree -p C2 | git apply --index && git commit -m "Master accepts moral equivalent of #2" @@ -516,4 +523,10 @@ test_expect_success 'format-patch --signoff' ' grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" ' +test_expect_success 'format-patch escapes From' ' + git format-patch more^..more --stdout > patch9 && + grep "^>From this" patch9 && + ! grep "^From this" patch9 +' + test_done diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 2ce24cd..5c6f0f4 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -168,6 +168,21 @@ test_expect_success 'no patch was sent' ' ! test -e commandline1 ' +test_expect_success 'fix >From lines' ' + clean_fake_sendmail && + cp $patches gt-from.patch && + echo ">From abcdef" >>gt-from.patch && + git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + gt-from.patch \ + 2>errors && + test -e msgtxt1 && + ! grep "^>From abcdef" msgtxt1 && + grep "^From abcdef" msgtxt1 +' + test_expect_success 'Author From: in message body' ' clean_fake_sendmail && git send-email \ -- 1.6.0.3