changeset 40893:e7110f44ee2d

commandserver: pass around option to hook repo instance creation This is necessary to wrap a repo instance so the master process will be notified on repo.close().
author Yuya Nishihara <yuya@tcha.org>
date Wed, 31 Oct 2018 21:57:11 +0900
parents 348352658e4b
children dc9901558e3c
files mercurial/chgserver.py mercurial/commandserver.py tests/test-commandserver.t
diffstat 3 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/chgserver.py	Sun Dec 09 19:40:54 2018 -0500
+++ b/mercurial/chgserver.py	Wed Oct 31 21:57:11 2018 +0900
@@ -313,10 +313,11 @@
 ]
 
 class chgcmdserver(commandserver.server):
-    def __init__(self, ui, repo, fin, fout, sock, hashstate, baseaddress):
+    def __init__(self, ui, repo, fin, fout, sock, prereposetups,
+                 hashstate, baseaddress):
         super(chgcmdserver, self).__init__(
             _newchgui(ui, channeledsystem(fin, fout, 'S'), self.attachio),
-            repo, fin, fout)
+            repo, fin, fout, prereposetups)
         self.clientsock = sock
         self._ioattached = False
         self._oldios = []  # original (self.ch, ui.fp, fd) before "attachio"
@@ -617,8 +618,8 @@
     def newconnection(self):
         self._lastactive = time.time()
 
-    def createcmdserver(self, repo, conn, fin, fout):
-        return chgcmdserver(self.ui, repo, fin, fout, conn,
+    def createcmdserver(self, repo, conn, fin, fout, prereposetups):
+        return chgcmdserver(self.ui, repo, fin, fout, conn, prereposetups,
                             self._hashstate, self._baseaddress)
 
 def chgunixservice(ui, repo, opts):
--- a/mercurial/commandserver.py	Sun Dec 09 19:40:54 2018 -0500
+++ b/mercurial/commandserver.py	Wed Oct 31 21:57:11 2018 +0900
@@ -196,7 +196,7 @@
     Listens for commands on fin, runs them and writes the output on a channel
     based stream to fout.
     """
-    def __init__(self, ui, repo, fin, fout):
+    def __init__(self, ui, repo, fin, fout, prereposetups=None):
         self.cwd = encoding.getcwd()
 
         if repo:
@@ -208,6 +208,7 @@
         else:
             self.ui = ui
             self.repo = self.repoui = None
+        self._prereposetups = prereposetups
 
         self.cdebug = channeledoutput(fout, 'd')
         self.cerr = channeledoutput(fout, 'e')
@@ -294,7 +295,8 @@
                 ui.setconfig('ui', 'nontty', 'true', 'commandserver')
 
         req = dispatch.request(args[:], copiedui, self.repo, self.cin,
-                               self.cout, self.cerr, self.cmsg)
+                               self.cout, self.cerr, self.cmsg,
+                               prereposetups=self._prereposetups)
 
         try:
             ret = dispatch.dispatch(req) & 255
@@ -420,12 +422,12 @@
     # same state inherited from parent.
     random.seed()
 
-def _serverequest(ui, repo, conn, createcmdserver):
+def _serverequest(ui, repo, conn, createcmdserver, prereposetups):
     fin = conn.makefile(r'rb')
     fout = conn.makefile(r'wb')
     sv = None
     try:
-        sv = createcmdserver(repo, conn, fin, fout)
+        sv = createcmdserver(repo, conn, fin, fout, prereposetups)
         try:
             sv.serve()
         # handle exceptions that may be raised by command server. most of
@@ -484,10 +486,10 @@
     def newconnection(self):
         """Called when main process notices new connection"""
 
-    def createcmdserver(self, repo, conn, fin, fout):
+    def createcmdserver(self, repo, conn, fin, fout, prereposetups):
         """Create new command server instance; called in the process that
         serves for the current connection"""
-        return server(self.ui, repo, fin, fout)
+        return server(self.ui, repo, fin, fout, prereposetups)
 
 class unixforkingservice(object):
     """
@@ -619,6 +621,7 @@
         _initworkerprocess()
         h = self._servicehandler
         try:
-            _serverequest(self.ui, self.repo, conn, h.createcmdserver)
+            _serverequest(self.ui, self.repo, conn, h.createcmdserver,
+                          prereposetups=None)  # TODO: pass in hook functions
         finally:
             gc.collect()  # trigger __del__ since worker process uses os._exit
--- a/tests/test-commandserver.t	Sun Dec 09 19:40:54 2018 -0500
+++ b/tests/test-commandserver.t	Wed Oct 31 21:57:11 2018 +0900
@@ -848,10 +848,10 @@
 
   $ cat <<'EOF' > ../earlycrasher.py
   > from mercurial import commandserver, extensions
-  > def _serverequest(orig, ui, repo, conn, createcmdserver):
+  > def _serverequest(orig, ui, repo, conn, createcmdserver, prereposetups):
   >     def createcmdserver(*args, **kwargs):
   >         raise Exception('crash')
-  >     return orig(ui, repo, conn, createcmdserver)
+  >     return orig(ui, repo, conn, createcmdserver, prereposetups)
   > def extsetup(ui):
   >     extensions.wrapfunction(commandserver, b'_serverequest', _serverequest)
   > EOF