server: move service factory from hgweb
authorYuya Nishihara <yuya@tcha.org>
Sat, 15 Oct 2016 14:09:36 +0900
changeset 30509 add7bcad1d9c
parent 30508 9195bc4cb816
child 30510 a0878bc87379
server: move service factory from hgweb
mercurial/commands.py
mercurial/hgweb/__init__.py
mercurial/server.py
--- a/mercurial/commands.py	Sat Oct 15 14:06:46 2016 +0900
+++ b/mercurial/commands.py	Sat Oct 15 14:09:36 2016 +0900
@@ -51,7 +51,6 @@
     hbisect,
     help,
     hg,
-    hgweb,
     localrepo,
     lock as lockmod,
     merge as mergemod,
@@ -6300,7 +6299,7 @@
     if opts["cmdserver"]:
         service = server.createcmdservice(ui, repo, opts)
     else:
-        service = hgweb.createservice(ui, repo, opts)
+        service = server.createhgwebservice(ui, repo, opts)
     return server.runservice(opts, initfn=service.init, runfn=service.run)
 
 @command('^status|st',
--- a/mercurial/hgweb/__init__.py	Sat Oct 15 14:06:46 2016 +0900
+++ b/mercurial/hgweb/__init__.py	Sat Oct 15 14:09:36 2016 +0900
@@ -85,39 +85,6 @@
     def run(self):
         self.httpd.serve_forever()
 
-def createservice(ui, repo, opts):
-    # this way we can check if something was given in the command-line
-    if opts.get('port'):
-        opts['port'] = util.getport(opts.get('port'))
-
-    alluis = set([ui])
-    if repo:
-        baseui = repo.baseui
-        alluis.update([repo.baseui, repo.ui])
-    else:
-        baseui = ui
-    webconf = opts.get('web_conf') or opts.get('webdir_conf')
-    if webconf:
-        # load server settings (e.g. web.port) to "copied" ui, which allows
-        # hgwebdir to reload webconf cleanly
-        servui = ui.copy()
-        servui.readconfig(webconf, sections=['web'])
-        alluis.add(servui)
-    else:
-        servui = ui
-
-    optlist = ("name templates style address port prefix ipv6"
-               " accesslog errorlog certificate encoding")
-    for o in optlist.split():
-        val = opts.get(o, '')
-        if val in (None, ''): # should check against default options instead
-            continue
-        for u in alluis:
-            u.setconfig("web", o, val, 'serve')
-
-    app = createapp(baseui, repo, webconf)
-    return httpservice(servui, app, opts)
-
 def createapp(baseui, repo, webconf):
     if webconf:
         return hgwebdir_mod.hgwebdir(webconf, baseui=baseui)
--- a/mercurial/server.py	Sat Oct 15 14:06:46 2016 +0900
+++ b/mercurial/server.py	Sat Oct 15 14:09:36 2016 +0900
@@ -17,6 +17,7 @@
 from . import (
     commandserver,
     error,
+    hgweb,
     util,
 )
 
@@ -118,3 +119,36 @@
         return _cmdservicemap[mode](ui, repo, opts)
     except KeyError:
         raise error.Abort(_('unknown mode %s') % mode)
+
+def createhgwebservice(ui, repo, opts):
+    # this way we can check if something was given in the command-line
+    if opts.get('port'):
+        opts['port'] = util.getport(opts.get('port'))
+
+    alluis = set([ui])
+    if repo:
+        baseui = repo.baseui
+        alluis.update([repo.baseui, repo.ui])
+    else:
+        baseui = ui
+    webconf = opts.get('web_conf') or opts.get('webdir_conf')
+    if webconf:
+        # load server settings (e.g. web.port) to "copied" ui, which allows
+        # hgwebdir to reload webconf cleanly
+        servui = ui.copy()
+        servui.readconfig(webconf, sections=['web'])
+        alluis.add(servui)
+    else:
+        servui = ui
+
+    optlist = ("name templates style address port prefix ipv6"
+               " accesslog errorlog certificate encoding")
+    for o in optlist.split():
+        val = opts.get(o, '')
+        if val in (None, ''): # should check against default options instead
+            continue
+        for u in alluis:
+            u.setconfig("web", o, val, 'serve')
+
+    app = hgweb.createapp(baseui, repo, webconf)
+    return hgweb.httpservice(servui, app, opts)