[PATCH stable] patch: fix parsing patch files containing CRs not followed by LFs

Wagner Bruna wagner.bruna+mercurial at gmail.com
Mon Jul 4 23:45:36 UTC 2011


# HG changeset patch
# User Wagner Bruna <wbruna at softwareexpress.com.br>
# Date 1309820019 10800
# Branch stable
# Node ID 5a5490ee24d011b1d12459d8611448500b81c6e6
# Parent  24ecdbe7c5c80fe24786a71c33e3706ed747ee88
patch: fix parsing patch files containing CRs not followed by LFs

Since 1e64e1e12195 , patch lines containing a CR not followed by a LF
would be incorrectly splitten, causing a failure to apply the patch.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -593,7 +593,7 @@ class patchfile(object):
                 self.exists = backend.exists(self.fname)
             self.missing = False
             if data:
-                self.lines = data.splitlines(True)
+                self.lines = mdiff.splitnewlines(data)
             if self.mode is None:
                 self.mode = mode
             if self.lines:
diff --git a/tests/test-patch.t b/tests/test-patch.t
--- a/tests/test-patch.t
+++ b/tests/test-patch.t
@@ -46,9 +46,9 @@ Prepare source repo and patch:
   $ rm $HGRCPATH
   $ hg init c
   $ cd c
-  $ echo 0 > a
+  $ printf "a\rc" > a
   $ hg ci -A -m 0 a -d '0 0'
-  $ echo 1 >> a
+  $ printf "a\rb\rc" > a
   $ cat << eof > log
   > first line which can't start with '# '
   > # second line is a comment but that shouldn't be a problem.
@@ -73,7 +73,7 @@ Clone and apply patch:
   $ hg import ../c/p
   applying ../c/p
   $ hg log -v -r 1
-  changeset:   1:e8cc66fbbaa6
+  changeset:   1:cd0bde79c428
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000



More information about the Mercurial-devel mailing list