[PATCH 1 of 1] patch: generate .rej wihtout eol adaptation

Shun-ichi Goto shunichi.goto at gmail.com
Thu Dec 2 06:10:08 CST 2010


# HG changeset patch
# User Shun-ichi GOTO <shunichi.goto at gmail.com>
# Date 1291291758 -32400
# Node ID 28946a4e335acd72a8fbf308f9010ed786922539
# Parent  cec6140b0f3c8c00515dbf3589068d1e2d233fdf
patch: generate .rej wihtout eol adaptation

When patch.eol=auto and patch has CRLF content, filepatch generates
incorrect .rej file having CRCRLF. This is because
patchfile.write_rej() uses patchfile.writelines() which makes eol
adaptation although self.rej data is not normalized.

This changeset add optional boolean argument 'strict' to omit eol
adaptation and use it for .rej generation.

To reproduce this issue:
 1. make taget file having CRLF line ending
 2. make patch file having CRLF content line ending
 3. prepare patch which would conflict
 4. applying patch with option 'patch.eol=auto'
 5. check .rej file has CRCRLF <= incorrect!

diff -r cec6140b0f3c -r 28946a4e335a mercurial/patch.py
--- a/mercurial/patch.py	Thu Dec 02 18:14:04 2010 +0900
+++ b/mercurial/patch.py	Thu Dec 02 21:09:18 2010 +0900
@@ -425,7 +425,7 @@
         finally:
             fp.close()
 
-    def writelines(self, fname, lines):
+    def writelines(self, fname, lines, strict=False):
         # Ensure supplied data ends in fname, being a regular file or
         # a symlink. cmdutil.updatedir will -too magically- take care
         # of setting it to the proper type afterwards.
@@ -435,7 +435,9 @@
         else:
             fp = self.opener(fname, 'w')
         try:
-            if self.eolmode == 'auto':
+            if strict:
+                eol = None
+            elif self.eolmode == 'auto':
                 eol = self.eol
             elif self.eolmode == 'crlf':
                 eol = '\r\n'
@@ -508,7 +510,7 @@
                     if l[-1] != '\n':
                         yield "\n\ No newline at end of file\n"
 
-        self.writelines(fname, rejlines())
+        self.writelines(fname, rejlines(), strict=True)
 
     def apply(self, h):
         if not h.complete():


More information about the Mercurial-devel mailing list