diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -110,6 +110,24 @@ ui:: verbose;; Increase the amount of output printed. True or False. Default is False. +web:: + Web interface configuration. + name;; + Repository name to use in the web interface. Default is current + working directory. + address;; + Interface address to bind to. Default is all. + port;; + Port to listen on. Default is 8000. + ipv6;; + Whether to use IPv6. Default is false. + accesslog;; + Where to output the access log. Default is stdout. + errorlog;; + Where to output the error log. Default is stderr. + templates;; + Where to find the HTML templates. Default is install path. + AUTHOR ------ Bryan O'Sullivan . diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1087,16 +1087,9 @@ def serve(ui, repo, **opts): r = repo.addchangegroup(fin) respond("") - def openlog(opt, default): - if opts[opt] and opts[opt] != '-': - return open(opts[opt], 'w') - else: - return default - httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], opts["address"], opts["port"], opts["ipv6"], - openlog('accesslog', sys.stdout), - openlog('errorlog', sys.stderr)) + opts['accesslog'], opts['errorlog']) if ui.verbose: addr, port = httpd.socket.getsockname() if addr == '0.0.0.0': @@ -1368,9 +1361,9 @@ table = { (serve, [('A', 'accesslog', '', 'access log file'), ('E', 'errorlog', '', 'error log file'), - ('p', 'port', 8000, 'listen port'), + ('p', 'port', 0, 'listen port'), ('a', 'address', '', 'interface address'), - ('n', 'name', os.getcwd(), 'repository name'), + ('n', 'name', "", 'repository name'), ('', 'stdio', None, 'for remote clients'), ('t', 'templates', "", 'template map'), ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')], diff --git a/mercurial/hgweb.py b/mercurial/hgweb.py --- a/mercurial/hgweb.py +++ b/mercurial/hgweb.py @@ -119,7 +119,7 @@ class hgweb: maxfiles = 10 def __init__(self, path, name, templates = ""): - self.templates = templates or templatepath() + self.templates = templates self.reponame = name self.path = path self.mtime = -1 @@ -603,7 +603,9 @@ class hgweb: self.refresh() args = cgi.parse() - m = os.path.join(self.templates, "map") + t = self.templates or self.repo.ui.config("web", "templates", + templatepath()) + m = os.path.join(t, "map") if args.has_key('style'): b = os.path.basename("map-" + args['style'][0]) p = os.path.join(self.templates, b) @@ -615,9 +617,11 @@ class hgweb: if "?" in uri: uri = uri.split("?")[0] url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) + name = self.reponame or self.repo.ui.config("web", "name", os.getcwd()) + self.t = templater(m, self.filters, {"url":url, - "repo":self.reponame, + "repo":name, "header":header, "footer":footer, }) @@ -705,6 +709,26 @@ class hgweb: def create_server(path, name, templates, address, port, use_ipv6 = False, accesslog = sys.stdout, errorlog = sys.stderr): + def openlog(opt, default): + if opt and opt != '-': + return open(opt, 'w') + return default + + u = ui() + repo = repository(u, path) + if not address: + address = u.config("web", "address", "") + if not port: + print port + port = int(u.config("web", "port", 8000)) + if not use_ipv6: + use_ipv6 = u.configbool("web", "ipv6") + + accesslog = openlog(accesslog or u.config("web", "accesslog", "-"), + sys.stdout) + errorlog = openlog(errorlog or u.config("web", "errorlog", "-"), + sys.stderr) + import BaseHTTPServer class IPv6HTTPServer(BaseHTTPServer.HTTPServer):