Patchwork [4,of,8,chgtocore] server: move service factory from hgweb

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 22, 2016, 3:59 p.m.
Message ID <03857e7317d72b4d57ec.1479830397@mimosa>
Download mbox | patch
Permalink /patch/17703/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 22, 2016, 3:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1476508176 -32400
#      Sat Oct 15 14:09:36 2016 +0900
# Node ID 03857e7317d72b4d57ecb54894dda31e6124931a
# Parent  bb4b6d8aeea5e7f9ce62b15679285040016f7bb1
server: move service factory from hgweb

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -51,7 +51,6 @@  from . import (
     hbisect,
     help,
     hg,
-    hgweb,
     localrepo,
     lock as lockmod,
     merge as mergemod,
@@ -6451,7 +6450,7 @@  def serve(ui, repo, **opts):
     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',
diff --git a/mercurial/hgweb/__init__.py b/mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py
+++ b/mercurial/hgweb/__init__.py
@@ -85,39 +85,6 @@  class httpservice(object):
     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)
diff --git a/mercurial/server.py b/mercurial/server.py
--- a/mercurial/server.py
+++ b/mercurial/server.py
@@ -17,6 +17,7 @@  from .i18n import _
 from . import (
     commandserver,
     error,
+    hgweb,
     util,
 )
 
@@ -118,3 +119,36 @@  def createcmdservice(ui, repo, opts):
         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)