# HG changeset patch # User Yuya Nishihara # Date 2017-10-02 06:18:24 # Node ID 163fa0aea71ea8524036b248a3db2837866e1124 # Parent b09b3eaf9c969f900339943988c5930dc6768e40 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