util: add helper to convert between LF and native EOL
authorYuya Nishihara <yuya@tcha.org>
Wed, 29 Mar 2017 21:40:15 +0900
changeset 31777 6a5b69b0abec
parent 31776 fe9b33bcec6a
child 31778 ac69675fff1c
util: add helper to convert between LF and native EOL See the next patch for why.
mercurial/util.py
--- a/mercurial/util.py	Wed Mar 29 21:28:54 2017 +0900
+++ b/mercurial/util.py	Wed Mar 29 21:40:15 2017 +0900
@@ -2211,6 +2211,13 @@
 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