Patchwork [1,of,2,chg-tests-fix,V3] dispatch: move IOError handling and flushing of streams to `dispatch()`

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 10, 2020, 9:11 a.m.
Message ID <96c66ca3f189d522dd53.1607591504@DESKTOP-STQPTJK>
Download mbox | patch
Permalink /patch/47856/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 10, 2020, 9:11 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1607588516 -19800
#      Thu Dec 10 13:51:56 2020 +0530
# Node ID 96c66ca3f189d522dd53c736919e7343c29e6116
# Parent  6de68a9dd7302f077edd73ea6d639d725ecf89b9
# EXP-Topic chg-test
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.
Yuya Nishihara - Dec. 10, 2020, 10:31 a.m.
On Thu, 10 Dec 2020 14:41:44 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1607588516 -19800
> #      Thu Dec 10 13:51:56 2020 +0530
> # Node ID 96c66ca3f189d522dd53c736919e7343c29e6116
> # Parent  6de68a9dd7302f077edd73ea6d639d725ecf89b9
> # EXP-Topic chg-test
> dispatch: move IOError handling and flushing of streams to `dispatch()`

Queued, thanks.

> -def closestdio(ui, err):
> +def flushstdio(ui, err):

Renamed to _flushstdio as the function interface is very specific to
dispatch().

Patch

diff -r 6de68a9dd730 -r 96c66ca3f189 mercurial/commandserver.py
--- a/mercurial/commandserver.py	Fri Apr 03 20:30:36 2020 +0530
+++ b/mercurial/commandserver.py	Thu Dec 10 13:51:56 2020 +0530
@@ -355,17 +355,7 @@ 
         )
 
         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
-
+            status = self._dispatchcommand(req)
             ret = status & 255
             # If shutdown-on-interrupt is off, it's important to write the
             # result code *after* SIGINT handler removed. If the result code
diff -r 6de68a9dd730 -r 96c66ca3f189 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Fri Apr 03 20:30:36 2020 +0530
+++ 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:
diff -r 6de68a9dd730 -r 96c66ca3f189 tests/test-devel-warnings.t
--- a/tests/test-devel-warnings.t	Fri Apr 03 20:30:36 2020 +0530
+++ b/tests/test-devel-warnings.t	Thu Dec 10 13:51:56 2020 +0530
@@ -104,6 +104,7 @@ 
    */hg:* in <module> (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 <module> (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 @@ 
    */hg:* in <module> (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 @@ 
    */hg:* in <module> (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 @@ 
    */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 @@ 
    */hg:* in <module> (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 @@ 
    */hg:* in <module> (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 @@ 
    */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)