# HG changeset patch # User Yuya Nishihara # Date 2017-03-29 12:43:38 # Node ID ac69675fff1caacf143ab7f0bda668e6e325670a # Parent 6a5b69b0abec0f943795a3178ab0d77fb2eb1120 ui: use bytes IO and convert EOL manually in ui.editor() Text IO sucks on Python 3 as it must be a unicode stream. We could introduce a wrapper that converts unicode back to bytes, but it wouldn't be simple to handle offsets transparently from/to underlying IOBase API. Fortunately, we don't need to process huge text files, so let's stick to bytes IO and convert EOL in memory. diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -1232,11 +1232,11 @@ class ui(object): if self.configbool('experimental', 'editortmpinhg'): rdir = repopath (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-', - suffix=extra['suffix'], text=True, + suffix=extra['suffix'], dir=rdir) try: - f = os.fdopen(fd, pycompat.sysstr("w")) - f.write(encoding.strfromlocal(text)) + f = os.fdopen(fd, r'wb') + f.write(util.tonativeeol(text)) f.close() environ = {'HGUSER': user} @@ -1258,8 +1258,8 @@ class ui(object): onerr=error.Abort, errprefix=_("edit failed"), blockedtag='editor') - f = open(name) - t = encoding.strtolocal(f.read()) + f = open(name, r'rb') + t = util.fromnativeeol(f.read()) f.close() finally: os.unlink(name)