##// END OF EJS Templates
hgweb: let staticfile() look up path from default location unless provided...
Martin von Zweigbergk -
r45938:dc9fe90b default
parent child Browse files
Show More
@@ -21,6 +21,7 b' from ..pycompat import ('
21 from .. import (
21 from .. import (
22 encoding,
22 encoding,
23 pycompat,
23 pycompat,
24 templater,
24 util,
25 util,
25 )
26 )
26
27
@@ -178,7 +179,7 b' def ispathsafe(path):'
178 return True
179 return True
179
180
180
181
181 def staticfile(directory, fname, res):
182 def staticfile(templatepath, directory, fname, res):
182 """return a file inside directory with guessed Content-Type header
183 """return a file inside directory with guessed Content-Type header
183
184
184 fname always uses '/' as directory separator and isn't allowed to
185 fname always uses '/' as directory separator and isn't allowed to
@@ -190,6 +191,11 b' def staticfile(directory, fname, res):'
190 if not ispathsafe(fname):
191 if not ispathsafe(fname):
191 return
192 return
192
193
194 if not directory:
195 tp = templatepath or templater.templatedir()
196 if tp is not None:
197 directory = os.path.join(tp, b'static')
198
193 fpath = os.path.join(*fname.split(b'/'))
199 fpath = os.path.join(*fname.split(b'/'))
194 path = os.path.join(directory, fpath)
200 path = os.path.join(directory, fpath)
195 try:
201 try:
@@ -413,12 +413,7 b' class hgwebdir(object):'
413 else:
413 else:
414 fname = req.qsparams[b'static']
414 fname = req.qsparams[b'static']
415 static = self.ui.config(b"web", b"static", untrusted=False)
415 static = self.ui.config(b"web", b"static", untrusted=False)
416 if not static:
416 staticfile(self.templatepath, static, fname, res)
417 tp = self.templatepath or templater.templatedir()
418 if tp is not None:
419 static = os.path.join(tp, b'static')
420
421 staticfile(static, fname, res)
422 return res.sendresponse()
417 return res.sendresponse()
423
418
424 # top-level index
419 # top-level index
@@ -36,7 +36,6 b' from .. import ('
36 revsetlang,
36 revsetlang,
37 scmutil,
37 scmutil,
38 smartset,
38 smartset,
39 templater,
40 templateutil,
39 templateutil,
41 )
40 )
42
41
@@ -1318,12 +1317,7 b' def static(web):'
1318 # a repo owner may set web.static in .hg/hgrc to get any file
1317 # a repo owner may set web.static in .hg/hgrc to get any file
1319 # readable by the user running the CGI script
1318 # readable by the user running the CGI script
1320 static = web.config(b"web", b"static", untrusted=False)
1319 static = web.config(b"web", b"static", untrusted=False)
1321 if not static:
1320 staticfile(web.templatepath, static, fname, web.res)
1322 tp = web.templatepath or templater.templatedir()
1323 if tp is not None:
1324 static = os.path.join(tp, b'static')
1325
1326 staticfile(static, fname, web.res)
1327 return web.res.sendresponse()
1321 return web.res.sendresponse()
1328
1322
1329
1323
General Comments 0
You need to be logged in to leave comments. Login now