Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dispatch.py @ 46102:49b6910217f9
dispatch: move IOError handling and flushing of streams to `dispatch()`
Instead of patching both dispatch code and commandserver code, we directly
handle this in `dispatch.dispatch()`.
Thanks to Yuya who recommended this.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 10 Dec 2020 13:51:56 +0530 |
parents | ac9de799d390 |
children | db5dddb38f5b |
line wrap: on
line diff
--- a/mercurial/dispatch.py Wed Dec 09 00:00:19 2020 -0800 +++ b/mercurial/dispatch.py Thu Dec 10 13:51:56 2020 +0530 @@ -104,7 +104,7 @@ raise exc -def closestdio(ui, err): +def _flushstdio(ui, err): status = None # In all cases we try to flush stdio streams. if util.safehasattr(ui, b'fout'): @@ -139,16 +139,8 @@ initstdio() with tracing.log('parse args into request'): req = request(pycompat.sysargv[1:]) - err = None - try: - status = dispatch(req) - except error.StdioError as e: - err = e - status = -1 - ret = closestdio(req.ui, err) - if ret: - status = ret + status = dispatch(req) _silencestdio() except KeyboardInterrupt: # Catch early/late KeyboardInterrupt as last ditch. Here nothing will @@ -240,7 +232,21 @@ def dispatch(req): """run the command specified in req.args; returns an integer status code""" - with tracing.log('dispatch.dispatch'): + err = None + try: + status = _rundispatch(req) + except error.StdioError as e: + err = e + status = -1 + + ret = _flushstdio(req.ui, err) + if ret: + status = ret + return status + + +def _rundispatch(req): + with tracing.log('dispatch._rundispatch'): if req.ferr: ferr = req.ferr elif req.ui: