changeset 30507:dd539e2d89aa

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.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Oct 2016 13:57:17 +0900
parents d9d8d78e6bc9
children 9195bc4cb816
files hgext/chgserver.py mercurial/commands.py mercurial/commandserver.py mercurial/server.py
diffstat 4 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/chgserver.py	Sat Oct 15 13:47:43 2016 +0900
+++ b/hgext/chgserver.py	Sat Oct 15 13:57:17 2016 +0900
@@ -60,6 +60,7 @@
     error,
     extensions,
     osutil,
+    server,
     util,
 )
 
@@ -635,7 +636,7 @@
     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.
--- a/mercurial/commands.py	Sat Oct 15 13:47:43 2016 +0900
+++ b/mercurial/commands.py	Sat Oct 15 13:57:17 2016 +0900
@@ -35,7 +35,6 @@
     bundle2,
     changegroup,
     cmdutil,
-    commandserver,
     copies,
     dagparser,
     dagutil,
@@ -6299,7 +6298,7 @@
         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)
--- a/mercurial/commandserver.py	Sat Oct 15 13:47:43 2016 +0900
+++ b/mercurial/commandserver.py	Sat Oct 15 13:57:17 2016 +0900
@@ -529,15 +529,3 @@
             _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)
--- a/mercurial/server.py	Sat Oct 15 13:47:43 2016 +0900
+++ b/mercurial/server.py	Sat Oct 15 13:57:17 2016 +0900
@@ -15,6 +15,7 @@
 from .i18n import _
 
 from . import (
+    commandserver,
     error,
     util,
 )
@@ -105,3 +106,15 @@
 
     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)