diff -r 9195bc4cb816 -r add7bcad1d9c mercurial/server.py --- 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)