# HG changeset patch # User Yuya Nishihara # Date 1476507437 -32400 # 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 -r d9d8d78e6bc9 -r dd539e2d89aa hgext/chgserver.py --- 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. diff -r d9d8d78e6bc9 -r dd539e2d89aa mercurial/commands.py --- 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) diff -r d9d8d78e6bc9 -r dd539e2d89aa mercurial/commandserver.py --- 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) diff -r d9d8d78e6bc9 -r dd539e2d89aa mercurial/server.py --- 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)