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