[PATCH 1 of 3] hgweb: move httpservice object from commands module

Yuya Nishihara yuya at tcha.org
Tue Nov 24 13:53:06 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1446296265 -32400
#      Sat Oct 31 21:57:45 2015 +0900
# Node ID 7a6e49b5ad9203fae2fd23ece832aea9c2d6ea0b
# Parent  397baacd694d0f8343888b64c200bfa926cdd893
hgweb: move httpservice object from commands module

This avoids the deep import of hgweb.server at the commands module.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -15,7 +15,6 @@ import patch, help, encoding, templatekw
 import archival, changegroup, cmdutil, hbisect
 import sshserver, hgweb
 import extensions
-from hgweb import server as hgweb_server
 import merge as mergemod
 import minirst, revset, fileset
 import dagparser, context, simplemerge, graphmod, copies
@@ -5969,52 +5968,9 @@ def serve(ui, repo, **opts):
         o = repo
 
     app = hgweb.hgweb(o, baseui=baseui)
-    service = httpservice(ui, app, opts)
+    service = hgweb.httpservice(ui, app, opts)
     cmdutil.service(opts, initfn=service.init, runfn=service.run)
 
-class httpservice(object):
-    def __init__(self, ui, app, opts):
-        self.ui = ui
-        self.app = app
-        self.opts = opts
-
-    def init(self):
-        util.setsignalhandler()
-        self.httpd = hgweb_server.create_server(self.ui, self.app)
-
-        if self.opts['port'] and not self.ui.verbose:
-            return
-
-        if self.httpd.prefix:
-            prefix = self.httpd.prefix.strip('/') + '/'
-        else:
-            prefix = ''
-
-        port = ':%d' % self.httpd.port
-        if port == ':80':
-            port = ''
-
-        bindaddr = self.httpd.addr
-        if bindaddr == '0.0.0.0':
-            bindaddr = '*'
-        elif ':' in bindaddr: # IPv6
-            bindaddr = '[%s]' % bindaddr
-
-        fqaddr = self.httpd.fqaddr
-        if ':' in fqaddr:
-            fqaddr = '[%s]' % fqaddr
-        if self.opts['port']:
-            write = self.ui.status
-        else:
-            write = self.ui.write
-        write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
-              (fqaddr, port, prefix, bindaddr, self.httpd.port))
-        self.ui.flush()  # avoid buffering of status message
-
-    def run(self):
-        self.httpd.serve_forever()
-
-
 @command('^status|st',
     [('A', 'all', None, _('show status of all files')),
     ('m', 'modified', None, _('show only modified files')),
diff --git a/mercurial/hgweb/__init__.py b/mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py
+++ b/mercurial/hgweb/__init__.py
@@ -10,9 +10,16 @@ from __future__ import absolute_import
 
 import os
 
+from ..i18n import _
+
+from .. import (
+    util,
+)
+
 from . import (
     hgweb_mod,
     hgwebdir_mod,
+    server,
 )
 
 def hgweb(config, name=None, baseui=None):
@@ -35,3 +42,44 @@ def hgweb(config, name=None, baseui=None
 def hgwebdir(config, baseui=None):
     return hgwebdir_mod.hgwebdir(config, baseui=baseui)
 
+class httpservice(object):
+    def __init__(self, ui, app, opts):
+        self.ui = ui
+        self.app = app
+        self.opts = opts
+
+    def init(self):
+        util.setsignalhandler()
+        self.httpd = server.create_server(self.ui, self.app)
+
+        if self.opts['port'] and not self.ui.verbose:
+            return
+
+        if self.httpd.prefix:
+            prefix = self.httpd.prefix.strip('/') + '/'
+        else:
+            prefix = ''
+
+        port = ':%d' % self.httpd.port
+        if port == ':80':
+            port = ''
+
+        bindaddr = self.httpd.addr
+        if bindaddr == '0.0.0.0':
+            bindaddr = '*'
+        elif ':' in bindaddr: # IPv6
+            bindaddr = '[%s]' % bindaddr
+
+        fqaddr = self.httpd.fqaddr
+        if ':' in fqaddr:
+            fqaddr = '[%s]' % fqaddr
+        if self.opts['port']:
+            write = self.ui.status
+        else:
+            write = self.ui.write
+        write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
+              (fqaddr, port, prefix, bindaddr, self.httpd.port))
+        self.ui.flush()  # avoid buffering of status message
+
+    def run(self):
+        self.httpd.serve_forever()


More information about the Mercurial-devel mailing list