Mercurial > hg
diff mercurial/hgweb/__init__.py @ 27139:d73f23344dc7
hgweb: extract factory function of httpservice object
The next patch will merge the cmdutil.service() calls of both commandserver
and hgweb. Before doing it, this patch wipes out the code specific to hgweb
from commands.serve().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 31 Oct 2015 22:15:16 +0900 |
parents | ea8e27e6098d |
children | a9cecc7b68d3 |
line wrap: on
line diff
--- a/mercurial/hgweb/__init__.py Sat Oct 31 21:57:45 2015 +0900 +++ b/mercurial/hgweb/__init__.py Sat Oct 31 22:15:16 2015 +0900 @@ -13,6 +13,7 @@ from ..i18n import _ from .. import ( + error, util, ) @@ -83,3 +84,32 @@ 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')) + + if repo: + baseui = repo.baseui + else: + baseui = 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 + baseui.setconfig("web", o, val, 'serve') + if repo and repo.ui != baseui: + repo.ui.setconfig("web", o, val, 'serve') + + o = opts.get('web_conf') or opts.get('webdir_conf') + if not o: + if not repo: + raise error.RepoError(_("there is no Mercurial repository" + " here (.hg not found)")) + o = repo + + app = hgweb(o, baseui=baseui) + return httpservice(ui, app, opts)