[PATCH 2 of 4] dispatch: move initialization of sys.std* files
Yuya Nishihara
yuya at tcha.org
Wed Oct 4 10:53:55 EDT 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1506925104 -3600
# Mon Oct 02 07:18:24 2017 +0100
# Node ID 2b071e9303f748de41c02efdea158883d336224a
# Parent bc4545271d0456e83e49667e1613057918f38093
dispatch: move initialization of sys.std* files
I'll add another Python 3 hack.
diff --git a/contrib/hgperf b/contrib/hgperf
--- a/contrib/hgperf
+++ b/contrib/hgperf
@@ -94,7 +94,4 @@ def runcommand(lui, repo, cmd, fullargs,
dispatch.runcommand = runcommand
-for fp in (sys.stdin, sys.stdout, sys.stderr):
- util.setbinary(fp)
-
dispatch.run()
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -37,11 +37,5 @@ except ImportError:
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()
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -75,6 +75,7 @@ class request(object):
def run():
"run the command in sys.argv"
+ _initstdio()
req = request(pycompat.sysargv[1:])
err = None
try:
@@ -95,6 +96,10 @@ def run():
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
More information about the Mercurial-devel
mailing list