[PATCH 1 of 4] commandserver: unindent superfluous "if True" blocks

Yuya Nishihara yuya at tcha.org
Sun Jul 17 14:02:59 UTC 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1463822053 -32400
#      Sat May 21 18:14:13 2016 +0900
# Node ID 3df2dc92d3a7c47cd79bd7ad44d6c3bf5679dbda
# Parent  1cc5a918b7d8acdc918809d74842fecc128c4ec4
commandserver: unindent superfluous "if True" blocks

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -581,13 +581,12 @@ class chgunixservicehandler(object):
         pass
 
     def shouldexit(self):
-        if True:  # TODO: unindent
-            if not self.issocketowner():
-                _log('%s is not owned, exiting.\n' % self.address)
-                return True
-            if time.time() - self.lastactive > self.idletimeout:
-                _log('being idle too long. exiting.\n')
-                return True
+        if not self.issocketowner():
+            _log('%s is not owned, exiting.\n' % self.address)
+            return True
+        if time.time() - self.lastactive > self.idletimeout:
+            _log('being idle too long. exiting.\n')
+            return True
         return False
 
     def newconnection(self):
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -340,51 +340,50 @@ class pipeservice(object):
             _restoreio(ui, fin, fout)
 
 def _serverequest(ui, repo, conn, createcmdserver):
-    if True:  # TODO: unindent
-        # use a different process group from the master process, making this
-        # process pass kernel "is_current_pgrp_orphaned" check so signals like
-        # SIGTSTP, SIGTTIN, SIGTTOU are not ignored.
-        os.setpgid(0, 0)
-        # change random state otherwise forked request handlers would have a
-        # same state inherited from parent.
-        random.seed()
+    # use a different process group from the master process, making this
+    # process pass kernel "is_current_pgrp_orphaned" check so signals like
+    # SIGTSTP, SIGTTIN, SIGTTOU are not ignored.
+    os.setpgid(0, 0)
+    # change random state otherwise forked request handlers would have a
+    # same state inherited from parent.
+    random.seed()
 
-        fin = conn.makefile('rb')
-        fout = conn.makefile('wb')
-        sv = None
+    fin = conn.makefile('rb')
+    fout = conn.makefile('wb')
+    sv = None
+    try:
+        sv = createcmdserver(repo, conn, fin, fout)
         try:
-            sv = createcmdserver(repo, conn, fin, fout)
-            try:
-                sv.serve()
-            # handle exceptions that may be raised by command server. most of
-            # known exceptions are caught by dispatch.
-            except error.Abort as inst:
-                ui.warn(_('abort: %s\n') % inst)
-            except IOError as inst:
-                if inst.errno != errno.EPIPE:
-                    raise
-            except KeyboardInterrupt:
-                pass
-            finally:
-                sv.cleanup()
-        except: # re-raises
-            # also write traceback to error channel. otherwise client cannot
-            # see it because it is written to server's stderr by default.
-            if sv:
-                cerr = sv.cerr
-            else:
-                cerr = channeledoutput(fout, 'e')
-            traceback.print_exc(file=cerr)
-            raise
+            sv.serve()
+        # handle exceptions that may be raised by command server. most of
+        # known exceptions are caught by dispatch.
+        except error.Abort as inst:
+            ui.warn(_('abort: %s\n') % inst)
+        except IOError as inst:
+            if inst.errno != errno.EPIPE:
+                raise
+        except KeyboardInterrupt:
+            pass
         finally:
-            fin.close()
-            try:
-                fout.close()  # implicit flush() may cause another EPIPE
-            except IOError as inst:
-                if inst.errno != errno.EPIPE:
-                    raise
-            # trigger __del__ since ForkingMixIn uses os._exit
-            gc.collect()
+            sv.cleanup()
+    except: # re-raises
+        # also write traceback to error channel. otherwise client cannot
+        # see it because it is written to server's stderr by default.
+        if sv:
+            cerr = sv.cerr
+        else:
+            cerr = channeledoutput(fout, 'e')
+        traceback.print_exc(file=cerr)
+        raise
+    finally:
+        fin.close()
+        try:
+            fout.close()  # implicit flush() may cause another EPIPE
+        except IOError as inst:
+            if inst.errno != errno.EPIPE:
+                raise
+        # trigger __del__ since ForkingMixIn uses os._exit
+        gc.collect()
 
 class unixservicehandler(object):
     """Set of pluggable operations for unix-mode services


More information about the Mercurial-devel mailing list