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

login
register
mail settings
Submitter Matt Harbison
Date April 18, 2017, 12:34 a.m.
Message ID <op.yyu7veuu9lwrgf@envy>
Download mbox | patch
Permalink /patch/20254/
State Not Applicable
Headers show

Comments

Matt Harbison - April 18, 2017, 12:34 a.m.
On Mon, 17 Apr 2017 18:40:22 -0400, Sean Farley <sean@farley.io> wrote:

> 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 + '/'
>
> ?

Yeah, that's more clear.  A couple lines later also calls  
"req.env.get('REPO_NAME')", so it's probably worth a local variable.

Without this check, links in index.html change like this:

Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - April 18, 2017, 11:19 a.m.
On Mon, 17 Apr 2017 20:34:16 -0400, Matt Harbison wrote:
> On Mon, 17 Apr 2017 18:40:22 -0400, Sean Farley <sean@farley.io> wrote:
> 
> > 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 + '/'
> >
> > ?
> 
> Yeah, that's more clear.  A couple lines later also calls  
> "req.env.get('REPO_NAME')", so it's probably worth a local variable.
> 
> Without this check, links in index.html change like this:

We need to check the emptiness of the REPO_NAME string, not the existence
of the REPO_NAME key.

Patch

--- c:/Users/Matt/Projects/hg/tests/test-hgwebdir.t
+++ c:/Users/Matt/Projects/hg/tests/test-hgwebdir.t.err
@@ -1692,7 +1692,7 @@ 

    $ get-with-headers.py localhost:$HGPORT1 '' | grep 'index'
    <meta name="robots" content="index, nofollow" />
-     <a href="/rev/71a89161f014">add index file</a>
+     <a href="//rev/71a89161f014">add index file</a>

    $ killdaemons.py
_______________________________________________