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

login
register
mail settings
Submitter Yuya Nishihara
Date March 29, 2017, 2:46 p.m.
Message ID <c43fe15a4a4bec542b74.1490798800@mimosa>
Download mbox | patch
Permalink /patch/19821/
State Accepted
Headers show

Comments

Yuya Nishihara - March 29, 2017, 2:46 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.
David Soria Parra - March 31, 2017, 4:50 p.m.
On Wed, Mar 29, 2017 at 11:46:40PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@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
> 
Theese patches look good to me, and I would mark them pre-reviewed if I could.
Augie Fackler - April 3, 2017, 3:34 p.m.
On Fri, Mar 31, 2017 at 09:50:26AM -0700, David Soria Parra wrote:
> On Wed, Mar 29, 2017 at 11:46:40PM +0900, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@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
> >
> Theese patches look good to me, and I would mark them pre-reviewed if I could.

Queued these, thanks.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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