# HG changeset patch # User Brendan Cully # Date 2010-02-18 18:46:01 # Node ID a27af7229850d3e095aeb5a6d794abcb3d9deb75 # Parent e96597c8d0eae1e0a1d0c11757d2bf8cde741da8 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. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -157,8 +157,8 @@ def split(stream): 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 diff --git a/tests/test-import b/tests/test-import --- a/tests/test-import +++ b/tests/test-import @@ -372,3 +372,30 @@ hg import -d '0 0' a.patch hg parents -v cd .. +echo '% tricky header splitting' +cat > trickyheaders.patch < +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 .. diff --git a/tests/test-import.out b/tests/test-import.out --- a/tests/test-import.out +++ b/tests/test-import.out @@ -314,3 +314,20 @@ module: summary 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