[PATCH] patch: don't look for headers in diff lines
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Fri Apr 9 13:36:07 CDT 2010
# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1270838045 -7200
patch: don't look for headers in diff lines
If you have a diff line that matches a header line, the patch splitter
currently breaks your patch at this line. For example a line like:
+key: value
This can lead to "malformed patch" exceptions. Now fixed.
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -47,6 +47,9 @@
if inheader and line[0] in (' ', '\t'):
# continuation
return True
+ if line[0] in (' ', '-', '+'):
+ # diff line - don't check for header pattern in there
+ return False
l = line.split(': ', 1)
return len(l) == 2 and ' ' not in l[0]
diff --git a/tests/test-import b/tests/test-import
--- a/tests/test-import
+++ b/tests/test-import
@@ -474,3 +474,24 @@
hg sum
hg diff --git -c tip
cd ..
+
+echo '% diff lines looking like headers'
+hg init difflineslikeheaders
+cd difflineslikeheaders
+echo a >a
+echo b >b
+echo c >c
+hg ci -Am1
+
+echo "key: value" >>a
+echo "key: value" >>b
+echo "foo" >>c
+hg ci -m2
+
+hg up -C 0
+hg diff --git -c1 >want
+hg diff -c1 | hg import --no-commit -
+hg diff --git >have
+diff want have
+cd ..
+
diff --git a/tests/test-import.out b/tests/test-import.out
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -373,3 +373,9 @@
diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
old mode 100644
new mode 100755
+% diff lines looking like headers
+adding a
+adding b
+adding c
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+applying patch from stdin
More information about the Mercurial-devel
mailing list