# HG changeset patch # User Martin von Zweigbergk # Date 1598137424 25200 # Node ID dc9fe90bdbd52892e09336f98a34ef1ba6b56265 # Parent da3b7c80aa3404e1d92cfd48954839d4a555bf66 hgweb: let staticfile() look up path from default location unless provided This reduces duplication between the two callers. Differential Revision: https://phab.mercurial-scm.org/D8934 diff -r da3b7c80aa34 -r dc9fe90bdbd5 mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py Mon Aug 03 22:40:05 2020 -0700 +++ b/mercurial/hgweb/common.py Sat Aug 22 16:03:44 2020 -0700 @@ -21,6 +21,7 @@ from .. import ( encoding, pycompat, + templater, util, ) @@ -178,7 +179,7 @@ return True -def staticfile(directory, fname, res): +def staticfile(templatepath, directory, fname, res): """return a file inside directory with guessed Content-Type header fname always uses '/' as directory separator and isn't allowed to @@ -190,6 +191,11 @@ if not ispathsafe(fname): return + if not directory: + tp = templatepath or templater.templatedir() + if tp is not None: + directory = os.path.join(tp, b'static') + fpath = os.path.join(*fname.split(b'/')) path = os.path.join(directory, fpath) try: diff -r da3b7c80aa34 -r dc9fe90bdbd5 mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Mon Aug 03 22:40:05 2020 -0700 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Aug 22 16:03:44 2020 -0700 @@ -413,12 +413,7 @@ else: fname = req.qsparams[b'static'] static = self.ui.config(b"web", b"static", untrusted=False) - if not static: - tp = self.templatepath or templater.templatedir() - if tp is not None: - static = os.path.join(tp, b'static') - - staticfile(static, fname, res) + staticfile(self.templatepath, static, fname, res) return res.sendresponse() # top-level index diff -r da3b7c80aa34 -r dc9fe90bdbd5 mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py Mon Aug 03 22:40:05 2020 -0700 +++ b/mercurial/hgweb/webcommands.py Sat Aug 22 16:03:44 2020 -0700 @@ -36,7 +36,6 @@ revsetlang, scmutil, smartset, - templater, templateutil, ) @@ -1318,12 +1317,7 @@ # a repo owner may set web.static in .hg/hgrc to get any file # readable by the user running the CGI script static = web.config(b"web", b"static", untrusted=False) - if not static: - tp = web.templatepath or templater.templatedir() - if tp is not None: - static = os.path.join(tp, b'static') - - staticfile(static, fname, web.res) + staticfile(web.templatepath, static, fname, web.res) return web.res.sendresponse()