changeset 34533:163fa0aea71e

dispatch: move initialization of sys.std* files I'll add another Python 3 hack.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 02 Oct 2017 07:18:24 +0100
parents b09b3eaf9c96
children b3073e175c17
files contrib/hgperf hg mercurial/dispatch.py
diffstat 3 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/hgperf	Mon Oct 02 06:52:10 2017 +0100
+++ b/contrib/hgperf	Mon Oct 02 07:18:24 2017 +0100
@@ -94,7 +94,4 @@
 
 dispatch.runcommand = runcommand
 
-for fp in (sys.stdin, sys.stdout, sys.stderr):
-    util.setbinary(fp)
-
 dispatch.run()
--- a/hg	Mon Oct 02 06:52:10 2017 +0100
+++ b/hg	Mon Oct 02 07:18:24 2017 +0100
@@ -37,11 +37,5 @@
     sys.stderr.write("(check your install and PYTHONPATH)\n")
     sys.exit(-1)
 
-from mercurial import (
-    dispatch,
-    util,
-)
-for fp in (sys.stdin, sys.stdout, sys.stderr):
-    util.setbinary(fp)
-
+from mercurial import dispatch
 dispatch.run()
--- a/mercurial/dispatch.py	Mon Oct 02 06:52:10 2017 +0100
+++ b/mercurial/dispatch.py	Mon Oct 02 07:18:24 2017 +0100
@@ -75,6 +75,7 @@
 
 def run():
     "run the command in sys.argv"
+    _initstdio()
     req = request(pycompat.sysargv[1:])
     err = None
     try:
@@ -95,6 +96,10 @@
         req.ui.ferr.flush()
     sys.exit(status & 255)
 
+def _initstdio():
+    for fp in (sys.stdin, sys.stdout, sys.stderr):
+        util.setbinary(fp)
+
 def _getsimilar(symbols, value):
     sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio()
     # The cutoff for similarity here is pretty arbitrary. It should