git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] am: fix patch format detection for Thunderbird "Save As" emails
@ 2009-12-17 23:58 Stephen Boyd
  2009-12-18  0:15 ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: Stephen Boyd @ 2009-12-17 23:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

The patch detection wants to inspect all the headers of a rfc2822 message
and ensure that they look like header field names. The headers are always
separated from the message body with a blank line. When Thunderbird3 saves
the message the blank line separating the headers from the body includes a
CR. The patch detection is failing because a CRLF doesn't match /^$/. Fix
this by allowing a CR to exist on the separating line.
---

I'm not sure how portable \r in a sed invocation is. Perhaps just checking
that l1, l2, and l3 are rfc2822 header fields (or indented lines) is better
than trying to check all of the headers?

This seems related to

  am fails to apply patches for files with CRLF lineendings
  http://article.gmane.org/gmane.comp.version-control.git/135229

but seems necessary because check_patch_format() is called before any
splitting with mailsplit is done (where I assume the fix for the issue
will be done).

 git-am.sh     |    2 +-
 t/t4150-am.sh |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 4838cdb..bb106b7 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -204,7 +204,7 @@ check_patch_format () {
 			# discarding the indented remainder of folded lines,
 			# and see if it looks like that they all begin with the
 			# header field names...
-			sed -n -e '/^$/q' -e '/^[ 	]/d' -e p "$1" |
+			sed -n -e '/^\r*$/q' -e '/^[ 	]/d' -e p "$1" |
 			sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
 			patch_format=mbox
 		fi
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 8296605..578bc81 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -83,6 +83,12 @@ test_expect_success setup '
 		echo "X-Fake-Field: Line Three" &&
 		git format-patch --stdout first | sed -e "1d"
 	} > patch1.eml &&
+	{
+		echo "X-Fake-Field: Line One" &&
+		echo "X-Fake-Field: Line Two" &&
+		echo "X-Fake-Field: Line Three" &&
+		git format-patch --stdout first | sed -e "1d"
+	} | sed -e "s/$/\r/" > patch1-crlf.eml &&
 	sed -n -e "3,\$p" msg >file &&
 	git add file &&
 	test_tick &&
@@ -123,6 +129,15 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
 	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
+test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
+	git checkout first &&
+	git am patch1-crlf.eml &&
+	! test -d .git/rebase-apply &&
+	test -z "$(git diff second)" &&
+	test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
+	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
+'
+
 GIT_AUTHOR_NAME="Another Thor"
 GIT_AUTHOR_EMAIL="a.thor@example.com"
 GIT_COMMITTER_NAME="Co M Miter"
-- 
1.6.6.rc3.1.g8df51

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-01-21 18:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-17 23:58 [PATCH] am: fix patch format detection for Thunderbird "Save As" emails Stephen Boyd
2009-12-18  0:15 ` Junio C Hamano
2009-12-18 21:34   ` [PATCHv2] " Stephen Boyd
2009-12-18 21:42     ` Eric Blake
2009-12-18 21:59       ` Stephen Boyd
2009-12-18 22:42         ` Eric Blake
2009-12-19  2:24           ` Stephen Boyd
2009-12-19  5:38             ` Eric Blake
2009-12-19  6:21               ` Stephen Boyd
2009-12-19  7:07                 ` Stephen Boyd
2009-12-19  7:39                   ` Junio C Hamano
2009-12-19 11:49                     ` Stephen Boyd
2009-12-19 10:26                 ` Andreas Schwab
2009-12-18 23:49       ` Junio C Hamano
2010-01-05 22:38     ` Nanako Shiraishi
2010-01-21 18:51       ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).