Patchwork [3,of,8] commandserver: remove redundant "if True" block

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 6, 2018, 12:45 p.m.
Message ID <92023422fbe3cf05e6d2.1544100310@mimosa>
Download mbox | patch
Permalink /patch/37025/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 6, 2018, 12:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540990987 -32400
#      Wed Oct 31 22:03:07 2018 +0900
# Node ID 92023422fbe3cf05e6d25b8213bd1e5a749c8e98
# Parent  c9533007e0e09fe8129b46208dbb760ff8799a88
commandserver: remove redundant "if True" block

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -570,35 +570,34 @@  class unixforkingservice(object):
 
     def _acceptnewconnection(self, sock, selector):
         h = self._servicehandler
-        if True:
+        try:
+            conn, _addr = sock.accept()
+        except socket.error as inst:
+            if inst.args[0] == errno.EINTR:
+                return
+            raise
+
+        pid = os.fork()
+        if pid:
             try:
-                conn, _addr = sock.accept()
-            except socket.error as inst:
-                if inst.args[0] == errno.EINTR:
-                    return
-                raise
-
-            pid = os.fork()
-            if pid:
+                self.ui.log(b'cmdserver', b'forked worker process (pid=%d)\n',
+                            pid)
+                self._workerpids.add(pid)
+                h.newconnection()
+            finally:
+                conn.close()  # release handle in parent process
+        else:
+            try:
+                selector.close()
+                sock.close()
+                self._runworker(conn)
+                conn.close()
+                os._exit(0)
+            except:  # never return, hence no re-raises
                 try:
-                    self.ui.log(b'cmdserver',
-                                b'forked worker process (pid=%d)\n', pid)
-                    self._workerpids.add(pid)
-                    h.newconnection()
+                    self.ui.traceback(force=True)
                 finally:
-                    conn.close()  # release handle in parent process
-            else:
-                try:
-                    selector.close()
-                    sock.close()
-                    self._runworker(conn)
-                    conn.close()
-                    os._exit(0)
-                except:  # never return, hence no re-raises
-                    try:
-                        self.ui.traceback(force=True)
-                    finally:
-                        os._exit(255)
+                    os._exit(255)
 
     def _sigchldhandler(self, signal, frame):
         self._reapworkers(os.WNOHANG)