hgwebdir: allow a repository to be hosted at "/"
This can be useful in general, but will also be useful for hosting subrepos,
with the main repo at /.
--- a/mercurial/hgweb/hgweb_mod.py Fri Apr 14 00:03:30 2017 -0700
+++ b/mercurial/hgweb/hgweb_mod.py Fri Mar 31 23:00:41 2017 -0400
@@ -335,7 +335,7 @@
req.url = req.env['SCRIPT_NAME']
if not req.url.endswith('/'):
req.url += '/'
- if 'REPO_NAME' in req.env:
+ if req.env.get('REPO_NAME'):
req.url += req.env['REPO_NAME'] + '/'
if 'PATH_INFO' in req.env:
--- a/mercurial/hgweb/hgwebdir_mod.py Fri Apr 14 00:03:30 2017 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py Fri Mar 31 23:00:41 2017 -0400
@@ -257,7 +257,7 @@
repos = dict(self.repos)
- if not virtual or (virtual == 'index' and virtual not in repos):
+ if (not virtual or virtual == 'index') and virtual not in repos:
req.respond(HTTP_OK, ctype)
return self.makeindex(req, tmpl)
@@ -269,8 +269,17 @@
req.respond(HTTP_OK, ctype)
return self.makeindex(req, tmpl, subdir)
- virtualrepo = virtual
- while virtualrepo:
+ def _virtualdirs():
+ # Check the full virtual path, each parent, and the root ('')
+ if virtual != '':
+ yield virtual
+
+ for p in util.finddirs(virtual):
+ yield p
+
+ yield ''
+
+ for virtualrepo in _virtualdirs():
real = repos.get(virtualrepo)
if real:
req.env['REPO_NAME'] = virtualrepo
@@ -284,11 +293,6 @@
except error.RepoError as inst:
raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
- up = virtualrepo.rfind('/')
- if up < 0:
- break
- virtualrepo = virtualrepo[:up]
-
# browse subdirectories
subdir = virtual + '/'
if [r for r in repos if r.startswith(subdir)]:
--- a/tests/test-hgwebdir.t Fri Apr 14 00:03:30 2017 -0700
+++ b/tests/test-hgwebdir.t Fri Mar 31 23:00:41 2017 -0400
@@ -1680,6 +1680,22 @@
$ killdaemons.py
+ $ cat > paths.conf << EOF
+ > [paths]
+ > / = $root/a
+ > EOF
+ $ hg serve -p $HGPORT1 -d --pid-file hg.pid --webdir-conf paths.conf
+ $ cat hg.pid >> $DAEMON_PIDS
+
+ $ hg id http://localhost:$HGPORT1
+ 71a89161f014
+
+ $ get-with-headers.py localhost:$HGPORT1 '' | grep 'index'
+ <meta name="robots" content="index, nofollow" />
+ <a href="/rev/71a89161f014">add index file</a>
+
+ $ killdaemons.py
+
paths errors 1
$ cat error-paths-1.log