dispatch: indent run() function
authorYuya Nishihara <yuya@tcha.org>
Mon, 13 Jul 2020 21:06:34 +0900
changeset 45101 9e6b86a8f438
parent 45100 d50d922ca02b
child 45102 efcc87d37f4d
dispatch: indent run() function I'll add KeyboardInterrupt handling there.
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Thu Jul 09 19:16:52 2020 +0900
+++ b/mercurial/dispatch.py	Mon Jul 13 21:06:34 2020 +0900
@@ -104,41 +104,44 @@
 
 def run():
     """run the command in sys.argv"""
-    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
-
-    # In all cases we try to flush stdio streams.
-    if util.safehasattr(req.ui, b'fout'):
-        assert req.ui is not None  # help pytype
-        assert req.ui.fout is not None  # help pytype
+        initstdio()
+        with tracing.log('parse args into request'):
+            req = request(pycompat.sysargv[1:])
+        err = None
         try:
-            req.ui.fout.flush()
-        except IOError as e:
+            status = dispatch(req)
+        except error.StdioError as e:
             err = e
             status = -1
 
-    if util.safehasattr(req.ui, b'ferr'):
-        assert req.ui is not None  # help pytype
-        assert req.ui.ferr is not None  # help pytype
-        try:
-            if err is not None and err.errno != errno.EPIPE:
-                req.ui.ferr.write(
-                    b'abort: %s\n' % encoding.strtolocal(err.strerror)
-                )
-            req.ui.ferr.flush()
-        # There's not much we can do about an I/O error here. So (possibly)
-        # change the status code and move on.
-        except IOError:
-            status = -1
+        # In all cases we try to flush stdio streams.
+        if util.safehasattr(req.ui, b'fout'):
+            assert req.ui is not None  # help pytype
+            assert req.ui.fout is not None  # help pytype
+            try:
+                req.ui.fout.flush()
+            except IOError as e:
+                err = e
+                status = -1
 
-    _silencestdio()
+        if util.safehasattr(req.ui, b'ferr'):
+            assert req.ui is not None  # help pytype
+            assert req.ui.ferr is not None  # help pytype
+            try:
+                if err is not None and err.errno != errno.EPIPE:
+                    req.ui.ferr.write(
+                        b'abort: %s\n' % encoding.strtolocal(err.strerror)
+                    )
+                req.ui.ferr.flush()
+            # There's not much we can do about an I/O error here. So (possibly)
+            # change the status code and move on.
+            except IOError:
+                status = -1
+
+        _silencestdio()
+    finally:
+        pass
     sys.exit(status & 255)