[PATCH 2 of 5] pycompat: provide bytes os.linesep

Yuya Nishihara yuya at tcha.org
Wed Mar 29 10:46:38 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1490790208 -32400
#      Wed Mar 29 21:23:28 2017 +0900
# Node ID 0b1a6949c3a05cab2b3a7028501a071d3dfea127
# Parent  267ba0ee66701fa87ff1764323599c299cff3e1f
pycompat: provide bytes os.linesep

diff --git a/hgext/eol.py b/hgext/eol.py
--- a/hgext/eol.py
+++ b/hgext/eol.py
@@ -101,6 +101,7 @@ from mercurial import (
     error,
     extensions,
     match,
+    pycompat,
     util,
 )
 
@@ -170,7 +171,7 @@ class eolfile(object):
 
         isrepolf = self.cfg.get('repository', 'native') != 'CRLF'
         self._encode['NATIVE'] = isrepolf and 'to-lf' or 'to-crlf'
-        iswdlf = ui.config('eol', 'native', os.linesep) in ('LF', '\n')
+        iswdlf = ui.config('eol', 'native', pycompat.oslinesep) in ('LF', '\n')
         self._decode['NATIVE'] = iswdlf and 'to-lf' or 'to-crlf'
 
         include = []
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -42,6 +42,7 @@ if ispy3:
     fsencode = os.fsencode
     fsdecode = os.fsdecode
     # A bytes version of os.name.
+    oslinesep = os.linesep.encode('ascii')
     osname = os.name.encode('ascii')
     ospathsep = os.pathsep.encode('ascii')
     ossep = os.sep.encode('ascii')
@@ -231,6 +232,7 @@ else:
     strkwargs = identity
     byteskwargs = identity
 
+    oslinesep = os.linesep
     osname = os.name
     ospathsep = os.pathsep
     ossep = os.sep
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1102,7 +1102,7 @@ class ui(object):
 
         # When stdin is in binary mode on Windows, it can cause
         # raw_input() to emit an extra trailing carriage return
-        if os.linesep == '\r\n' and line and line[-1] == '\r':
+        if pycompat.oslinesep == '\r\n' and line and line[-1] == '\r':
             line = line[:-1]
         return line
 


More information about the Mercurial-devel mailing list