[PATCH 1 of 2] py3: decode prompt string before calling rawinput

Denis Laxalde denis at laxalde.org
Wed Oct 9 09:29:23 EDT 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1570627696 -7200
#      Wed Oct 09 15:28:16 2019 +0200
# Node ID 99f06850be3ecc521ba461684686865c1191c5a0
# Parent  1fcf79e9943a17a2e7ae19954b2b5ad5972f8fff
py3: decode prompt string before calling rawinput

Calling input() (aka pycompat.rawinput() on python3) with a byte string
displays a byte string in the console. E.g. in interactive commit, we
get: b"examine changes to '<file>'?\n(enter ? for help) [Ynesfdaq?]".
Similarly, "hg email" prompts are messed up.

We thus decode the prompt string before running rawinput().

diff --git a/mercurial/ui.py b/mercurial/ui.py
index b8cac79..432f53e 100644
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1555,6 +1555,7 @@ class ui(object):
         # - http://bugs.python.org/issue12833
         with self.timeblockedsection(b'stdio'):
             if usereadline:
+                prompt = encoding.strfromlocal(prompt)
                 line = encoding.strtolocal(pycompat.rawinput(prompt))
                 # When stdin is in binary mode on Windows, it can cause
                 # raw_input() to emit an extra trailing carriage return


More information about the Mercurial-devel mailing list