diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py --- a/mercurial/commandserver.py +++ b/mercurial/commandserver.py @@ -355,18 +355,7 @@ class server(object): ) try: - err = None - try: - status = self._dispatchcommand(req) - except error.StdioError as e: - status = -1 - err = e - - retval = dispatch.closestdio(req.ui, err) - if retval: - status = retval - - ret = status & 255 + ret = self._dispatchcommand(req) & 255 # If shutdown-on-interrupt is off, it's important to write the # result code *after* SIGINT handler removed. If the result code # were lost, the client wouldn't be able to continue processing. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -104,7 +104,7 @@ class request(object): 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 @@ def run(): 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 _formatargs(args): 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: diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t --- a/tests/test-devel-warnings.t +++ b/tests/test-devel-warnings.t @@ -104,6 +104,7 @@ */hg:* in (glob) (?) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py* in callcatch (glob) @@ -120,6 +121,7 @@ */hg:* in (glob) (?) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob) @@ -142,6 +144,7 @@ */mercurial/commandserver.py:* in runcommand (glob) */mercurial/commandserver.py:* in _dispatchcommand (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob) @@ -184,6 +187,7 @@ Stripping from a transaction */hg:* in (glob) (?) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py* in callcatch (glob) @@ -201,6 +205,7 @@ Stripping from a transaction */hg:* in (glob) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob) @@ -223,6 +228,7 @@ Stripping from a transaction */mercurial/commandserver.py:* in runcommand (glob) */mercurial/commandserver.py:* in _dispatchcommand (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob) @@ -247,6 +253,7 @@ Stripping from a transaction */hg:* in (glob) (?) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py* in callcatch (glob) @@ -271,6 +278,7 @@ Stripping from a transaction */hg:* in (glob) */mercurial/dispatch.py:* in run (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob) @@ -293,6 +301,7 @@ Stripping from a transaction */mercurial/commandserver.py:* in runcommand (glob) */mercurial/commandserver.py:* in _dispatchcommand (glob) */mercurial/dispatch.py:* in dispatch (glob) + */mercurial/dispatch.py:* in _rundispatch (glob) */mercurial/dispatch.py:* in _runcatch (glob) */mercurial/dispatch.py:* in _callcatch (glob) */mercurial/scmutil.py:* in callcatch (glob)