changeset 26450:1138e1d05207

util.system: compare fileno to see if it needs stdout redirection Future patches will reopen stdout to be line-buffered, so sys.stdout may be different object than sys.__stdout__.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 03 Oct 2015 14:57:24 +0900
parents 89b7a7883aee
children c8f42c1926a5
files mercurial/util.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Fri Oct 02 23:04:52 2015 -0700
+++ b/mercurial/util.py	Sat Oct 03 14:57:24 2015 +0900
@@ -730,6 +730,10 @@
     global _hgexecutable
     _hgexecutable = path
 
+def _isstdout(f):
+    fileno = getattr(f, 'fileno', None)
+    return fileno and fileno() == sys.__stdout__.fileno()
+
 def system(cmd, environ=None, cwd=None, onerr=None, errprefix=None, out=None):
     '''enhanced shell command execution.
     run with environment maybe modified, maybe in different dir.
@@ -765,7 +769,7 @@
         env = dict(os.environ)
         env.update((k, py2shell(v)) for k, v in environ.iteritems())
         env['HG'] = hgexecutable()
-        if out is None or out == sys.__stdout__:
+        if out is None or _isstdout(out):
             rc = subprocess.call(cmd, shell=True, close_fds=closefds,
                                  env=env, cwd=cwd)
         else: