Patchwork [4,of,5] py3: open patch file in binary mode and convert eol manually

login
register
mail settings
Submitter Yuya Nishihara
Date March 10, 2018, 11:28 a.m.
Message ID <a984ebd44ac74e7b5329.1520681286@mimosa>
Download mbox | patch
Permalink /patch/29250/
State Accepted
Headers show

Comments

Yuya Nishihara - March 10, 2018, 11:28 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520678949 -32400
#      Sat Mar 10 19:49:09 2018 +0900
# Node ID a984ebd44ac74e7b532963a50e0714d93e4465e3
# Parent  d472860cb611fb3f268ae48bd2870432387eca5b
py3: open patch file in binary mode and convert eol manually

Here we don't introduce a reader wrapper since it wouldn't be easy to make
read(n) handle partial data and length correctly.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1120,9 +1120,10 @@  the hunk is left unchanged.
                         ui.warn(_("editor exited with exit code %d\n") % ret)
                         continue
                     # Remove comment lines
-                    patchfp = open(patchfn)
+                    patchfp = open(patchfn, r'rb')
                     ncpatchfp = stringio()
                     for line in util.iterfile(patchfp):
+                        line = util.fromnativeeol(line)
                         if not line.startswith('#'):
                             ncpatchfp.write(line)
                     patchfp.close()