[PATCH 2 of 8 chgtocore] server: move service table and factory from commandserver

Yuya Nishihara yuya at tcha.org
Tue Nov 22 10:59:55 EST 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1476507437 -32400
#      Sat Oct 15 13:57:17 2016 +0900
# Node ID aca8c3cfc3a5924dd99945baae3cb784c3c79c99
# Parent  f4d872cabe169528a1c82eae2206e4344a3ce892
server: move service table and factory from commandserver

This is necessary to solve future dependency cycle between commandserver.py
and chgserver.py.

'cmd' prefix is added to table and function names to avoid conflicts with
hgweb.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -60,6 +60,7 @@ from mercurial import (
     error,
     extensions,
     osutil,
+    server,
     util,
 )
 
@@ -635,7 +636,7 @@ def chgunixservice(ui, repo, opts):
     return commandserver.unixforkingservice(ui, repo=None, opts=opts, handler=h)
 
 def uisetup(ui):
-    commandserver._servicemap['chgunix'] = chgunixservice
+    server._cmdservicemap['chgunix'] = chgunixservice
 
     # CHGINTERNALMARK is temporarily set by chg client to detect if chg will
     # start another chg. drop it to avoid possible side effects.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -35,7 +35,6 @@ from . import (
     bundle2,
     changegroup,
     cmdutil,
-    commandserver,
     copies,
     dagparser,
     dagutil,
@@ -6450,7 +6449,7 @@ def serve(ui, repo, **opts):
         s.serve_forever()
 
     if opts["cmdserver"]:
-        service = commandserver.createservice(ui, repo, opts)
+        service = server.createcmdservice(ui, repo, opts)
     else:
         service = hgweb.createservice(ui, repo, opts)
     return server.runservice(opts, initfn=service.init, runfn=service.run)
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -529,15 +529,3 @@ class unixforkingservice(object):
             _serverequest(self.ui, self.repo, conn, h.createcmdserver)
         finally:
             gc.collect()  # trigger __del__ since worker process uses os._exit
-
-_servicemap = {
-    'pipe': pipeservice,
-    'unix': unixforkingservice,
-    }
-
-def createservice(ui, repo, opts):
-    mode = opts['cmdserver']
-    try:
-        return _servicemap[mode](ui, repo, opts)
-    except KeyError:
-        raise error.Abort(_('unknown mode %s') % mode)
diff --git a/mercurial/server.py b/mercurial/server.py
--- a/mercurial/server.py
+++ b/mercurial/server.py
@@ -15,6 +15,7 @@ import tempfile
 from .i18n import _
 
 from . import (
+    commandserver,
     error,
     util,
 )
@@ -105,3 +106,15 @@ def runservice(opts, parentfn=None, init
 
     if runfn:
         return runfn()
+
+_cmdservicemap = {
+    'pipe': commandserver.pipeservice,
+    'unix': commandserver.unixforkingservice,
+}
+
+def createcmdservice(ui, repo, opts):
+    mode = opts['cmdserver']
+    try:
+        return _cmdservicemap[mode](ui, repo, opts)
+    except KeyError:
+        raise error.Abort(_('unknown mode %s') % mode)


More information about the Mercurial-devel mailing list