diff mercurial/hgweb/common.py @ 45398:dc9fe90bdbd5

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
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 22 Aug 2020 16:03:44 -0700
parents 9a5c4875a88c
children ec2fc4d038c2
line wrap: on
line diff
--- 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: