# HG changeset patch # User Matt Harbison # Date 1488770552 18000 # Node ID da7d19324b1e3d2ce0636bf73e76bf8f3d68ed27 # Parent a7c687c351194bae8c15e70823fda596a173beda 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. diff -r a7c687c35119 -r da7d19324b1e mercurial/hgweb/hgwebdir_mod.py --- 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) + '/') diff -r a7c687c35119 -r da7d19324b1e tests/test-hgwebdir.t --- a/tests/test-hgwebdir.t Fri Mar 17 09:19:56 2017 -0700 +++ b/tests/test-hgwebdir.t Sun Mar 05 22:22:32 2017 -0500 @@ -1566,6 +1566,119 @@ /b/ /c/ + $ killdaemons.py + $ cat > paths.conf << EOF + > [paths] + > /dir1/a_repo = $root/a + > /dir1/a_repo/b_repo = $root/b + > /dir1/dir2/index = $root/b + > EOF + $ hg serve -p $HGPORT1 -d --pid-file hg.pid --webdir-conf paths.conf + $ cat hg.pid >> $DAEMON_PIDS + + $ echo 'index file' > $root/a/index + $ hg --cwd $root/a ci -Am 'add index file' + adding index + + $ get-with-headers.py localhost:$HGPORT1 '' | grep 'a_repo' + dir1/a_repo + + dir1/a_repo/b_repo + + + $ get-with-headers.py localhost:$HGPORT1 'index' | grep 'a_repo' + dir1/a_repo + + dir1/a_repo/b_repo + + + $ get-with-headers.py localhost:$HGPORT1 'dir1' | grep 'a_repo' + a_repo + + a_repo/b_repo + + + $ get-with-headers.py localhost:$HGPORT1 'dir1/index' | grep 'a_repo' + a_repo + + a_repo/b_repo + + + $ get-with-headers.py localhost:$HGPORT1 'dir1/a_repo' | grep 'a_repo' + + + + dir1/a_repo: log + href="/dir1/a_repo/atom-log" title="Atom feed for dir1/a_repo" /> + href="/dir1/a_repo/rss-log" title="RSS feed for dir1/a_repo" /> + mercurial +
  • graph
  • +
  • tags
  • +
  • bookmarks
  • +
  • branches
  • +
  • changeset
  • +
  • browse
  • +
  • help
  • + + + +