##// END OF EJS Templates
util: always force line buffered stdout when stdout is a tty (BC)...
Simon Farnsworth -
r30876:3a4c0905 default
parent child Browse files
Show More
@@ -87,14 +87,10 b' def _runpager(ui, p):'
87 87 close_fds=util.closefds, stdin=subprocess.PIPE,
88 88 stdout=util.stdout, stderr=util.stderr)
89 89
90 # back up original file objects and descriptors
91 olduifout = ui.fout
92 oldstdout = util.stdout
90 # back up original file descriptors
93 91 stdoutfd = os.dup(util.stdout.fileno())
94 92 stderrfd = os.dup(util.stderr.fileno())
95 93
96 # create new line-buffered stdout so that output can show up immediately
97 ui.fout = util.stdout = newstdout = os.fdopen(util.stdout.fileno(), 'wb', 1)
98 94 os.dup2(pager.stdin.fileno(), util.stdout.fileno())
99 95 if ui._isatty(util.stderr):
100 96 os.dup2(pager.stdin.fileno(), util.stderr.fileno())
@@ -103,15 +99,10 b' def _runpager(ui, p):'
103 99 def killpager():
104 100 if util.safehasattr(signal, "SIGINT"):
105 101 signal.signal(signal.SIGINT, signal.SIG_IGN)
106 pager.stdin.close()
107 ui.fout = olduifout
108 util.stdout = oldstdout
109 # close new stdout while it's associated with pager; otherwise stdout
110 # fd would be closed when newstdout is deleted
111 newstdout.close()
112 # restore original fds: stdout is open again
102 # restore original fds, closing pager.stdin copies in the process
113 103 os.dup2(stdoutfd, util.stdout.fileno())
114 104 os.dup2(stderrfd, util.stderr.fileno())
105 pager.stdin.close()
115 106 pager.wait()
116 107
117 108 def uisetup(ui):
@@ -63,9 +63,21 b' urlparse = pycompat.urlparse'
63 63 urlreq = pycompat.urlreq
64 64 xmlrpclib = pycompat.xmlrpclib
65 65
66 def isatty(fp):
67 try:
68 return fp.isatty()
69 except AttributeError:
70 return False
71
72 # glibc determines buffering on first write to stdout - if we replace a TTY
73 # destined stdout with a pipe destined stdout (e.g. pager), we want line
74 # buffering
75 if isatty(stdout):
76 stdout = os.fdopen(stdout.fileno(), 'wb', 1)
77
66 78 if pycompat.osname == 'nt':
67 79 from . import windows as platform
68 stdout = platform.winstdout(pycompat.stdout)
80 stdout = platform.winstdout(stdout)
69 81 else:
70 82 from . import posix as platform
71 83
@@ -2750,12 +2762,6 b' def removeauth(u):'
2750 2762 u.user = u.passwd = None
2751 2763 return str(u)
2752 2764
2753 def isatty(fp):
2754 try:
2755 return fp.isatty()
2756 except AttributeError:
2757 return False
2758
2759 2765 timecount = unitcountfn(
2760 2766 (1, 1e3, _('%.0f s')),
2761 2767 (100, 1, _('%.1f s')),
General Comments 0
You need to be logged in to leave comments. Login now