Patchwork [V4] hgwebdir: allow a repository to be hosted at "/"

login
register
mail settings
Submitter Matt Harbison
Date April 15, 2017, 7:34 p.m.
Message ID <3fd50d5f9314a96f43eb.1492284886@Envy>
Download mbox | patch
Permalink /patch/20231/
State Accepted
Headers show

Comments

Matt Harbison - April 15, 2017, 7:34 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1491015641 14400
#      Fri Mar 31 23:00:41 2017 -0400
# Node ID 3fd50d5f9314a96f43eb73480763f224c4d05831
# Parent  4c2c30bc38b4f84ce8f215146bbf158e299065b3
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 /.
Yuya Nishihara - April 16, 2017, 10:05 a.m.
On Sat, 15 Apr 2017 15:34:46 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1491015641 14400
> #      Fri Mar 31 23:00:41 2017 -0400
> # Node ID 3fd50d5f9314a96f43eb73480763f224c4d05831
> # Parent  4c2c30bc38b4f84ce8f215146bbf158e299065b3
> 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 /.

Queued, thanks.
Sean Farley - April 17, 2017, 10:40 p.m.
Kevin Bullock <kbullock+mercurial@ringworld.org> writes:

>> On Apr 15, 2017, at 14:34, Matt Harbison <mharbison72@gmail.com> wrote:
>> 
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1491015641 14400
>> #      Fri Mar 31 23:00:41 2017 -0400
>> # Node ID 3fd50d5f9314a96f43eb73480763f224c4d05831
>> # Parent  4c2c30bc38b4f84ce8f215146bbf158e299065b3
>> 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 /.
>> 
>> diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
>> --- a/mercurial/hgweb/hgweb_mod.py
>> +++ b/mercurial/hgweb/hgweb_mod.py
>> @@ -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'):
>
> Since we don't need the value returned from .get(), is there some other reason for this change that I'm not seeing?

'REPO_NAME' is used in the next line, so I guess this was supposed to
be:

foo = req.env.get('REPO_NAME')
if foo:
    req.url += foo + '/'

?

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -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:
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
@@ -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)]:
diff --git a/tests/test-hgwebdir.t b/tests/test-hgwebdir.t
--- a/tests/test-hgwebdir.t
+++ b/tests/test-hgwebdir.t
@@ -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