import: if in doubt, consume stream until start of diff stable
authorBrendan Cully <brendan@kublai.com>
Thu, 18 Feb 2010 10:46:01 -0800
branchstable
changeset 10501 a27af7229850
parent 10500 e96597c8d0ea
child 10502 1e022c88a0a5
import: if in doubt, consume stream until start of diff This prevents a header-like line in the message body from causing a spurious split.
mercurial/patch.py
tests/test-import
tests/test-import.out
--- a/mercurial/patch.py	Thu Feb 18 10:32:51 2010 +0100
+++ b/mercurial/patch.py	Thu Feb 18 10:46:01 2010 -0800
@@ -157,8 +157,8 @@
             if line.split(':', 1)[0].lower() in mimeheaders:
                 # let email parser handle this
                 return mimesplit(stream, cur)
-        elif inheader:
-            # No evil headers seen, split by hand
+        elif line.startswith('--- ') and inheader:
+            # No evil headers seen by diff start, split by hand
             return headersplit(stream, cur)
         # Not enough info, keep reading
 
--- a/tests/test-import	Thu Feb 18 10:32:51 2010 +0100
+++ b/tests/test-import	Thu Feb 18 10:46:01 2010 -0800
@@ -372,3 +372,30 @@
 hg parents -v
 cd ..
 
+echo '% tricky header splitting'
+cat > trickyheaders.patch <<EOF
+From: User A <user@a>
+Subject: [PATCH] from: tricky!
+
+# HG changeset patch
+# User User B
+# Date 1266264441 18000
+# Branch stable
+# Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
+# Parent  0000000000000000000000000000000000000000
+from: tricky!
+
+That is not a header.
+
+diff -r 000000000000 -r f2be6a1170ac foo
+--- /dev/null
++++ b/foo
+@@ -0,0 +1,1 @@
++foo
+EOF
+
+hg init trickyheaders
+cd trickyheaders
+hg import -d '0 0' ../trickyheaders.patch
+hg export --git tip
+cd ..
--- a/tests/test-import.out	Thu Feb 18 10:32:51 2010 +0100
+++ b/tests/test-import.out	Thu Feb 18 10:46:01 2010 -0800
@@ -314,3 +314,20 @@
 description
 
 
+% tricky header splitting
+applying ../trickyheaders.patch
+# HG changeset patch
+# User User B
+# Date 0 0
+# Node ID eb56ab91903632294ac504838508cb370c0901d2
+# Parent  0000000000000000000000000000000000000000
+from: tricky!
+
+That is not a header.
+
+diff --git a/foo b/foo
+new file mode 100644
+--- /dev/null
++++ b/foo
+@@ -0,0 +1,1 @@
++foo