diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -30,6 +30,7 @@ hg, hook, profiling, + pycompat, repoview, templatefilters, templater, @@ -60,6 +61,17 @@ ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)), )) +def getstyle(req, configfn, templatepath): + fromreq = req.form.get('style', [None])[0] + if fromreq is not None: + fromreq = pycompat.sysbytes(fromreq) + styles = ( + fromreq, + configfn('web', 'style'), + 'paper', + ) + return styles, templater.stylemap(styles, templatepath) + def makebreadcrumb(url, prefix=''): '''Return a 'URL breadcrumb' list @@ -170,12 +182,8 @@ # figure out which style to use vars = {} - styles = ( - req.form.get('style', [None])[0], - self.config('web', 'style'), - 'paper', - ) - style, mapfile = templater.stylemap(styles, self.templatepath) + styles, (style, mapfile) = getstyle(req, self.config, + self.templatepath) if style == styles[0]: vars['style'] = style diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -503,12 +503,8 @@ url += '/' vars = {} - styles = ( - req.form.get('style', [None])[0], - config('web', 'style'), - 'paper' - ) - style, mapfile = templater.stylemap(styles, self.templatepath) + styles, (style, mapfile) = hgweb_mod.getstyle(req, config, + self.templatepath) if style == styles[0]: vars['style'] = style