##// 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 close_fds=util.closefds, stdin=subprocess.PIPE,
87 close_fds=util.closefds, stdin=subprocess.PIPE,
88 stdout=util.stdout, stderr=util.stderr)
88 stdout=util.stdout, stderr=util.stderr)
89
89
90 # back up original file objects and descriptors
90 # back up original file descriptors
91 olduifout = ui.fout
92 oldstdout = util.stdout
93 stdoutfd = os.dup(util.stdout.fileno())
91 stdoutfd = os.dup(util.stdout.fileno())
94 stderrfd = os.dup(util.stderr.fileno())
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 os.dup2(pager.stdin.fileno(), util.stdout.fileno())
94 os.dup2(pager.stdin.fileno(), util.stdout.fileno())
99 if ui._isatty(util.stderr):
95 if ui._isatty(util.stderr):
100 os.dup2(pager.stdin.fileno(), util.stderr.fileno())
96 os.dup2(pager.stdin.fileno(), util.stderr.fileno())
@@ -103,15 +99,10 b' def _runpager(ui, p):'
103 def killpager():
99 def killpager():
104 if util.safehasattr(signal, "SIGINT"):
100 if util.safehasattr(signal, "SIGINT"):
105 signal.signal(signal.SIGINT, signal.SIG_IGN)
101 signal.signal(signal.SIGINT, signal.SIG_IGN)
106 pager.stdin.close()
102 # restore original fds, closing pager.stdin copies in the process
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
113 os.dup2(stdoutfd, util.stdout.fileno())
103 os.dup2(stdoutfd, util.stdout.fileno())
114 os.dup2(stderrfd, util.stderr.fileno())
104 os.dup2(stderrfd, util.stderr.fileno())
105 pager.stdin.close()
115 pager.wait()
106 pager.wait()
116
107
117 def uisetup(ui):
108 def uisetup(ui):
@@ -63,9 +63,21 b' urlparse = pycompat.urlparse'
63 urlreq = pycompat.urlreq
63 urlreq = pycompat.urlreq
64 xmlrpclib = pycompat.xmlrpclib
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 if pycompat.osname == 'nt':
78 if pycompat.osname == 'nt':
67 from . import windows as platform
79 from . import windows as platform
68 stdout = platform.winstdout(pycompat.stdout)
80 stdout = platform.winstdout(stdout)
69 else:
81 else:
70 from . import posix as platform
82 from . import posix as platform
71
83
@@ -2750,12 +2762,6 b' def removeauth(u):'
2750 u.user = u.passwd = None
2762 u.user = u.passwd = None
2751 return str(u)
2763 return str(u)
2752
2764
2753 def isatty(fp):
2754 try:
2755 return fp.isatty()
2756 except AttributeError:
2757 return False
2758
2759 timecount = unitcountfn(
2765 timecount = unitcountfn(
2760 (1, 1e3, _('%.0f s')),
2766 (1, 1e3, _('%.0f s')),
2761 (100, 1, _('%.1f s')),
2767 (100, 1, _('%.1f s')),
General Comments 0
You need to be logged in to leave comments. Login now