Patchwork [1,of,8] commandserver: pass around option to hook repo instance creation

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 6, 2018, 12:45 p.m.
Message ID <958a93f4f9210c4b5669.1544100308@mimosa>
Download mbox | patch
Permalink /patch/37023/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 6, 2018, 12:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540990631 -32400
#      Wed Oct 31 21:57:11 2018 +0900
# Node ID 958a93f4f9210c4b5669e4424f8d73b048ef72ed
# Parent  53bdf0ab321c90189c61beb021d8eac54cf40918
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().
Pulkit Goyal - Dec. 10, 2018, 1:19 p.m.
On Thu, Dec 6, 2018 at 3:47 PM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1540990631 -32400
> #      Wed Oct 31 21:57:11 2018 +0900
> # Node ID 958a93f4f9210c4b5669e4424f8d73b048ef72ed
> # Parent  53bdf0ab321c90189c61beb021d8eac54cf40918
> 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().
>

Queued 1-4, many thanks!

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -313,10 +313,11 @@  class channeledsystem(object):
 ]
 
 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 @@  class chgunixservicehandler(object):
     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):
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -196,7 +196,7 @@  class server(object):
     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 @@  class server(object):
         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 @@  class server(object):
                 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 @@  def _initworkerprocess():
     # 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 @@  class unixservicehandler(object):
     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 @@  class unixforkingservice(object):
         _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
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -848,10 +848,10 @@  unix domain socket:
 
   $ 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