commandserver: remove redundant "if True" block
authorYuya Nishihara <yuya@tcha.org>
Wed, 31 Oct 2018 22:03:07 +0900
changeset 53643 9f00de4dc7cb995aae9245fb8b0044fd45e476ad
parent 53642 dc9901558e3c6a78bad3f6594b3888f95104c443
child 53644 2525faf4ecdbe7418b47ea87fce24cb52e657308
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
commandserver: remove redundant "if True" block
mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -565,45 +565,44 @@ class unixforkingservice(object):
                 if exiting:
                     break
                 continue
             self._acceptnewconnection(self._sock, selector)
         selector.close()
 
     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)
 
     def _reapworkers(self, options):
         while self._workerpids:
             try:
                 pid, _status = os.waitpid(-1, options)