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

login
register
mail settings
Submitter Yuya Nishihara
Date June 30, 2016, 2:26 p.m.
Message ID <b00830fdf008c83d361b.1467296814@mimosa>
Download mbox | patch
Permalink /patch/15678/
State Accepted
Headers show

Comments

Yuya Nishihara - June 30, 2016, 2:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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().

Patch

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.