Mercurial > hg
changeset 7450:79d1bb737c16
hgweb: extend [paths] syntax to match repositories recursively (issue852)
This feature somehow duplicates [collections] but it is simpler to use and has
less issues under Windows where using absolute path as configuration file key
is not supported.
Suggested by Dirkjan Ochtman <dirkjan@ochtman.nl>
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 01 Dec 2008 14:20:20 +0100 |
parents | f848d7f96195 |
children | fca9947652ce |
files | contrib/hgwebdir.fcgi hgwebdir.cgi mercurial/hgweb/hgwebdir_mod.py tests/test-hgwebdir tests/test-hgwebdir.out |
diffstat | 5 files changed, 70 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/hgwebdir.fcgi Mon Dec 01 13:44:34 2008 +0100 +++ b/contrib/hgwebdir.fcgi Mon Dec 01 14:20:20 2008 +0100 @@ -29,12 +29,28 @@ # repos, collections of repos in a directory tree, or both. # # [paths] -# virtual/path = /real/path -# virtual/path = /real/path +# virtual/path1 = /real/path1 +# virtual/path2 = /real/path2 +# virtual/root = /real/root/* +# / = /real/root2/* # # [collections] # /prefix/to/strip/off = /root/of/tree/full/of/repos # +# paths example: +# +# * First two lines mount one repository into one virtual path, like +# '/real/path1' into 'virtual/path1'. +# +# * The third entry tells every mercurial repository found in +# '/real/root', recursively, should be mounted in 'virtual/root'. This +# format is preferred over the [collections] one, using absolute paths +# as configuration keys is not supported on every platform (including +# Windows). +# +# * The last entry is a special case mounting all repositories in +# '/real/root2' in the root of the virtual directory. +# # collections example: say directory tree /foo contains repos /foo/bar, # /foo/quux/baz. Give this config section: # [collections]
--- a/hgwebdir.cgi Mon Dec 01 13:44:34 2008 +0100 +++ b/hgwebdir.cgi Mon Dec 01 14:20:20 2008 +0100 @@ -28,12 +28,28 @@ # repos, collections of repos in a directory tree, or both. # # [paths] -# virtual/path = /real/path -# virtual/path = /real/path +# virtual/path1 = /real/path1 +# virtual/path2 = /real/path2 +# virtual/root = /real/root/* +# / = /real/root2/* # # [collections] # /prefix/to/strip/off = /root/of/tree/full/of/repos # +# paths example: +# +# * First two lines mount one repository into one virtual path, like +# '/real/path1' into 'virtual/path1'. +# +# * The third entry tells every mercurial repository found in +# '/real/root', recursively, should be mounted in 'virtual/root'. This +# format is preferred over the [collections] one, using absolute paths +# as configuration keys is not supported on every platform (including +# Windows). +# +# * The last entry is a special case mounting all repositories in +# /'real/root2' in the root of the virtual directory. +# # collections example: say directory tree /foo contains repos /foo/bar, # /foo/quux/baz. Give this config section: # [collections]
--- a/mercurial/hgweb/hgwebdir_mod.py Mon Dec 01 13:44:34 2008 +0100 +++ b/mercurial/hgweb/hgwebdir_mod.py Mon Dec 01 14:20:20 2008 +0100 @@ -51,7 +51,21 @@ if cp.has_option('web', 'baseurl'): self._baseurl = cp.get('web', 'baseurl') if cp.has_section('paths'): - self.repos.extend(cleannames(cp.items('paths'))) + paths = cleannames(cp.items('paths')) + for prefix, root in paths: + roothead, roottail = os.path.split(root) + if roottail != '*': + self.repos.append((prefix, root)) + continue + # "foo = /bar/*" makes every subrepo of /bar/ to be + # mounted as foo/subrepo + roothead = os.path.normpath(roothead) + for path in util.walkrepos(roothead, followsym=True): + path = os.path.normpath(path) + name = util.pconvert(path[len(roothead):]).strip('/') + if prefix: + name = prefix + '/' + name + self.repos.append((name, path)) if cp.has_section('collections'): for prefix, root in cp.items('collections'): for path in util.walkrepos(root, followsym=True):
--- a/tests/test-hgwebdir Mon Dec 01 13:44:34 2008 +0100 +++ b/tests/test-hgwebdir Mon Dec 01 14:20:20 2008 +0100 @@ -51,6 +51,7 @@ [paths] t/a/=$root/a b=$root/b +coll=$root/* EOF hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \ @@ -66,6 +67,9 @@ "$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/a/?style=atom' \ | sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//" "$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/a/file/tip/a?style=raw' +# Test [paths] '*' extension +"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/coll/?style=raw' +"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/coll/a/file/tip/a?style=raw' cat > collections.conf <<EOF [collections]
--- a/tests/test-hgwebdir.out Mon Dec 01 13:44:34 2008 +0100 +++ b/tests/test-hgwebdir.out Mon Dec 01 14:20:20 2008 +0100 @@ -30,6 +30,10 @@ /b/ +/coll/a/ +/coll/b/ +/coll/b/d/ +/coll/c/ /t/a/ 200 Script output follows @@ -103,6 +107,17 @@ 200 Script output follows a +200 Script output follows + + +/coll/a/ +/coll/b/ +/coll/b/d/ +/coll/c/ + +200 Script output follows + +a % should succeed 200 Script output follows