[PATCH 4 of 5] util: add helper to convert between LF and native EOL

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


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1490791215 -32400
#      Wed Mar 29 21:40:15 2017 +0900
# Node ID c43fe15a4a4bec542b7411087a1ad0233cb5614f
# Parent  24dce83e6706dfaad602e9ff0440ac40f6a4cc37
util: add helper to convert between LF and native EOL

See the next patch for why.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2208,6 +2208,13 @@ def tolf(s):
 def tocrlf(s):
     return _eolre.sub('\r\n', s)
 
+if pycompat.oslinesep == '\r\n':
+    tonativeeol = tocrlf
+    fromnativeeol = tolf
+else:
+    tonativeeol = pycompat.identity
+    fromnativeeol = pycompat.identity
+
 def escapestr(s):
     # call underlying function of s.encode('string_escape') directly for
     # Python 3 compatibility


More information about the Mercurial-devel mailing list