[PATCH 3 of 5 py3] ui: convert to/from Unicode on Python 3 in ui.editor()

Augie Fackler raf at durin42.com
Mon Mar 20 21:56:49 EDT 2017


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1489901890 14400
#      Sun Mar 19 01:38:10 2017 -0400
# Node ID 70ec92cd06b503cdba456f069c0f65bd71987a6e
# Parent  4136d2f283afab8b143a5392144652c079dedbaf
ui: convert to/from Unicode on Python 3 in ui.editor()

I considered making this I/O be done in terms of bytes, but that would
cause an observable regression for Windows users, as non-binary-mode
open does EOL conversion there. There are probably new encoding
dragons lurking here, so we may want to switch to using binary mode
and doing EOL conversion ourselves.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1196,7 +1196,7 @@ class ui(object):
                                       dir=rdir)
         try:
             f = os.fdopen(fd, pycompat.sysstr("w"))
-            f.write(text)
+            f.write(encoding.strfromlocal(text))
             f.close()
 
             environ = {'HGUSER': user}
@@ -1219,7 +1219,7 @@ class ui(object):
                         blockedtag='editor')
 
             f = open(name)
-            t = f.read()
+            t = encoding.strtolocal(f.read())
             f.close()
         finally:
             os.unlink(name)


More information about the Mercurial-devel mailing list