diff mercurial/hgweb/hgwebdir_mod.py @ 31482:da7d19324b1e

hgwebdir: add support for explicit index files This is useful for when repositories are nested in --web-conf, and in the future with hosted subrepositories. The previous behavior was only to render an index at each virtual directory. There is now an explicit 'index' child for each virtual directory. The name was suggested by Yuya, for consistency with the other method names. Additionally, there is now an explicit 'index' child for every repository directory with a nested repository somewhere below it. This seems more consistent with each virtual directory hosting an index, and more discoverable than to only have an index for a directory that directly hosts a nested repository. I couldn't figure out how to close the loop and provide one in each directory without a deeper nested repository, without blocking a committed 'index' file. Keeping that seems better than rendering an empty index.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Mar 2017 22:22:32 -0500
parents d7bf7d2bd5ab
children bd3cb917761a
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Fri Mar 17 09:19:56 2017 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sun Mar 05 22:22:32 2017 -0500
@@ -254,13 +254,21 @@
                 return []
 
             # top-level index
-            elif not virtual:
+
+            repos = dict(self.repos)
+
+            if not virtual or (virtual == 'index' and virtual not in repos):
                 req.respond(HTTP_OK, ctype)
                 return self.makeindex(req, tmpl)
 
             # nested indexes and hgwebs
 
-            repos = dict(self.repos)
+            if virtual.endswith('/index') and virtual not in repos:
+                subdir = virtual[:-len('index')]
+                if any(r.startswith(subdir) for r in repos):
+                    req.respond(HTTP_OK, ctype)
+                    return self.makeindex(req, tmpl, subdir)
+
             virtualrepo = virtual
             while virtualrepo:
                 real = repos.get(virtualrepo)
@@ -352,8 +360,7 @@
                             pass
 
                 parts = [name]
-                if 'PATH_INFO' in req.env:
-                    parts.insert(0, req.env['PATH_INFO'].rstrip('/'))
+                parts.insert(0, '/' + subdir.rstrip('/'))
                 if req.env['SCRIPT_NAME']:
                     parts.insert(0, req.env['SCRIPT_NAME'])
                 url = re.sub(r'/+', '/', '/'.join(parts) + '/')