[PATCH 2 of 3] commandserver: promote .cleanup() hook from chgserver

Yuya Nishihara yuya at tcha.org
Thu Jun 30 10:26:54 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1463811503 -32400
#      Sat May 21 15:18:23 2016 +0900
# Node ID b00830fdf008c83d361b05491b023778275dfd61
# Parent  ced2dca6ea44867d8b02d6026d38fa099c30c6c1
commandserver: promote .cleanup() hook from chgserver

This allows us to unify _requesthandler.handle().

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -349,6 +349,7 @@ class chgcmdserver(commandserver.server)
             self.capabilities['validate'] = chgcmdserver.validate
 
     def cleanup(self):
+        super(chgcmdserver, self).cleanup()
         # dispatch._runcatch() does not flush outputs if exception is not
         # handled by dispatch._dispatch()
         self.ui.flush()
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -179,6 +179,10 @@ class server(object):
 
         self.client = fin
 
+    def cleanup(self):
+        """release and restore resources taken during server session"""
+        pass
+
     def _read(self, size):
         if not size:
             return ''
@@ -329,6 +333,7 @@ class pipeservice(object):
             sv = server(ui, self.repo, fin, fout)
             return sv.serve()
         finally:
+            sv.cleanup()
             _restoreio(ui, fin, fout)
 
 class _requesthandler(socketserver.StreamRequestHandler):
@@ -348,6 +353,8 @@ class _requesthandler(socketserver.Strea
                     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.


More information about the Mercurial-devel mailing list