comparison mercurial/util.py @ 30908:3a4c0905f357

util: always force line buffered stdout when stdout is a tty (BC) pager replaced stdout with a line buffered version to work around glibc deciding on a buffering strategy on the first write to stdout. This is going to make my next patch hard, as replacing stdout will make tracking time spent blocked on it more challenging. Move the line buffering requirement to util.py, and remove it from pager. This means that the abuse of ui.formatted=True and pager set to cat or equivalent no longer results in a line-buffered output to a pipe, hence (BC), although I don't expect anyone to be affected
author Simon Farnsworth <simonfar@fb.com>
date Fri, 03 Feb 2017 15:10:27 -0800
parents 0126e422450e
children 82f1ef8b4477
comparison
equal deleted inserted replaced
30907:1791be8a95c5 30908:3a4c0905f357
61 urlerr = pycompat.urlerr 61 urlerr = pycompat.urlerr
62 urlparse = pycompat.urlparse 62 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
72 _ = i18n._ 84 _ = i18n._
73 85
2748 '''remove all authentication information from a url string''' 2760 '''remove all authentication information from a url string'''
2749 u = url(u) 2761 u = url(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')),
2762 (10, 1, _('%.2f s')), 2768 (10, 1, _('%.2f s')),
2763 (1, 1, _('%.3f s')), 2769 (1, 1, _('%.3f s')),