[PATCH 2 of 2] hgweb: resolve path backwards to locate repository
Markus Zapke-Gründemann
markuszapke at gmx.net
Wed Nov 28 10:58:46 CST 2012
# HG changeset patch
# User Markus Zapke-Gründemann <markus at keimlink.de>
# Date 1354121091 -3600
# Branch stable
# Node ID 5c4910af1fd62ab2681beb81ce7a4ad9ca7d7227
# Parent 24b51d1e0d0d8c17b71d3557f570d2c4fa0b9b9d
hgweb: resolve path backwards to locate repository
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
@@ -172,8 +172,6 @@ class hgwebdir(object):
def run_wsgi(self, req):
try:
try:
- self.refresh()
-
virtual = req.env.get("PATH_INFO", "").strip('/')
tmpl = self.templater(req)
ctype = tmpl('mimetype', encoding=encoding.encoding)
@@ -188,18 +186,26 @@ class hgwebdir(object):
static = templater.templatepath('static')
return (staticfile(static, fname, req),)
- # top-level index
- elif not virtual:
- req.respond(HTTP_OK, ctype)
- return self.makeindex(req, tmpl)
-
# nested indexes and hgwebs
-
- repos = dict(self.repos)
virtualrepo = virtual
+ real = nodescend = False
+ paths = self.getpaths(clean=True)
while virtualrepo:
- real = repos.get(virtualrepo)
- if real:
+ if virtualrepo in paths:
+ path = paths[virtualrepo]
+ if path.endswith('*'):
+ path = path.rsplit('/', 1)[0]
+ if virtualrepo == virtual:
+ nodescend = True
+ real = virtual.replace(virtualrepo, path)
+ break
+ up = virtualrepo.rfind('/')
+ if up < 0:
+ break
+ virtualrepo = virtualrepo[:up]
+ while real:
+ hgdir = os.path.join(real, '.hg')
+ if os.path.isdir(real) and os.path.isdir(hgdir):
req.env['REPO_NAME'] = virtualrepo
try:
repo = hg.repository(self.ui, real)
@@ -209,15 +215,20 @@ class hgwebdir(object):
raise ErrorResponse(HTTP_SERVER_ERROR, msg)
except error.RepoError, inst:
raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
+ up = real.rfind('/')
+ if nodescend or up < 0:
+ break
+ real = real[:up]
- up = virtualrepo.rfind('/')
- if up < 0:
- break
- virtualrepo = virtualrepo[:up]
+ # top-level index
+ self.refresh()
+ if not virtual:
+ req.respond(HTTP_OK, ctype)
+ return self.makeindex(req, tmpl)
# browse subdirectories
subdir = virtual + '/'
- if [r for r in repos if r.startswith(subdir)]:
+ if [r for r, ignore in self.repos if r.startswith(subdir)]:
req.respond(HTTP_OK, ctype)
return self.makeindex(req, tmpl, subdir)
More information about the Mercurial-devel
mailing list