Patchwork [STABLE] ui: flush before prompting for input with readline

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 2, 2019, 10:35 p.m.
Message ID <584cfb5d3d3c5cc78514.1572734118@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/42701/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 2, 2019, 10:35 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1572734019 25200
#      Sat Nov 02 15:33:39 2019 -0700
# Branch stable
# Node ID 584cfb5d3d3c5cc78514e8ed8f688b52fd60cf47
# Parent  5fae970ebefab080585d06d7783e9bcb424b09e9
ui: flush before prompting for input with readline

I was using `hg absorb` with Python 3 and noticed that the
prompt was appearing without any output about what would be
done. After I answered the prompt, the output was printed
to stdout.

This appears to be a buffering difference between Python 2
and Python 3.

To work around it, this commit adds an explicit flush() before
calling the raw input function when readline is used.
Yuya Nishihara - Nov. 3, 2019, 2:01 a.m.
On Sat, 02 Nov 2019 15:35:18 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1572734019 25200
> #      Sat Nov 02 15:33:39 2019 -0700
> # Branch stable
> # Node ID 584cfb5d3d3c5cc78514e8ed8f688b52fd60cf47
> # Parent  5fae970ebefab080585d06d7783e9bcb424b09e9
> ui: flush before prompting for input with readline

Queued for stable, thanks.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1564,6 +1564,7 @@  class ui(object):
         # - http://bugs.python.org/issue12833
         with self.timeblockedsection(b'stdio'):
             if usereadline:
+                self.flush()
                 prompt = encoding.strfromlocal(prompt)
                 line = encoding.strtolocal(pycompat.rawinput(prompt))
                 # When stdin is in binary mode on Windows, it can cause