--- a/hgext/pager.py Thu Feb 02 02:56:38 2017 -0800
+++ b/hgext/pager.py Fri Feb 03 15:10:27 2017 -0800
@@ -87,14 +87,10 @@
close_fds=util.closefds, stdin=subprocess.PIPE,
stdout=util.stdout, stderr=util.stderr)
- # back up original file objects and descriptors
- olduifout = ui.fout
- oldstdout = util.stdout
+ # back up original file descriptors
stdoutfd = os.dup(util.stdout.fileno())
stderrfd = os.dup(util.stderr.fileno())
- # create new line-buffered stdout so that output can show up immediately
- ui.fout = util.stdout = newstdout = os.fdopen(util.stdout.fileno(), 'wb', 1)
os.dup2(pager.stdin.fileno(), util.stdout.fileno())
if ui._isatty(util.stderr):
os.dup2(pager.stdin.fileno(), util.stderr.fileno())
@@ -103,15 +99,10 @@
def killpager():
if util.safehasattr(signal, "SIGINT"):
signal.signal(signal.SIGINT, signal.SIG_IGN)
- pager.stdin.close()
- ui.fout = olduifout
- util.stdout = oldstdout
- # close new stdout while it's associated with pager; otherwise stdout
- # fd would be closed when newstdout is deleted
- newstdout.close()
- # restore original fds: stdout is open again
+ # restore original fds, closing pager.stdin copies in the process
os.dup2(stdoutfd, util.stdout.fileno())
os.dup2(stderrfd, util.stderr.fileno())
+ pager.stdin.close()
pager.wait()
def uisetup(ui):