# HG changeset patch # User Yuya Nishihara # Date 2016-10-15 04:57:17 # Node ID dd539e2d89aaf1c0308ba1d6da12cef77273041c # Parent d9d8d78e6bc9c648272a09d67135f4628622f780 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, @@ -6299,7 +6298,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)