[PATCH] serve: automatically include local subrepos

Mike Williams mrw at eandem.co.uk
Tue Feb 22 03:43:10 CST 2011


On 21/02/2011 23:51, Matt Mackall wrote:
> On Mon, 2011-02-21 at 23:02 +0000, Mike Williams wrote:
>> # HG changeset patch
>> # User Mike Williams<mrw at eandem.co.uk>
>> # Date 1298326556 0
>> # Branch stable
>> # Node ID 4efda2d5cec947ba63086fa64355bb7a14f39df2
>> # Parent  b3f9af7c22c5241be2eea24140cc6a3c834f9b59
>> serve: automatically include local subrepos
>>
>> Mercurial wont locally serve subrepos without a web configuration file.  This
>> duplicates information already held in the .hgsub file.
>>
>> This change checks for local subrepos when sharing a single repo.
>
> First, we're in a code freeze until March 1.

Apologies, I thought it would go on a pending pile until after the 
freeze.  Possibly not the best time to have my baptism of fire in 
supplying patches.

> Second, this patch doesn't fit in with the subrepo design philosophy.
> We make a point of NOT looking into changesets to figure out what
> subrepos are involved when we don't have a working directory context.
> For starters, there's no reason to think that there will be a uniquely
> relevant and correct changeset. There could be many on many different
> branches, and one or more of them could be buggy. Further, there's no
> reason to think those subrepos will be -Mercurial- subrepos.
>
> Thus knowledge of subrepos is strictly in the domain of clients which
> have working directories.

I thought I had picked up the working directory but I see now I hadn't 
sorry.  I also thought I had filtered subrepos to be mercurial ones 
only, I must not yet understand what subrepo.status() returns.

> A more acceptable way to do this would be:
>
> - make the single-repo mode of hgweb a special case of hgwebdir

Ok, will need to do more code reading.

> - add a flag to the hgweb scripts to include recursively include
> subdirectories by default

includesubrepos?  would there be an interaction with descend?

> - add a command-line switch to 'hg serve' to do the same

A switch of -S would be consistent with other commands with extended 
subrepo behaviour.

Assuming you are still happy with the idea of automatically picking up 
subrepos for single repo views with a working directory I'll start 
looking into this unless someone else beats me to the punch.

> ps: your patch seems to assume that repositories are always relative
> paths on the same machine and that there are no possible security issue
> with following them.

Yeah, another fail.  Plus I didn't handle where there were no local hg 
subrepos.

>> diff -r b3f9af7c22c5 -r 4efda2d5cec9 mercurial/hgweb/__init__.py
>> --- a/mercurial/hgweb/__init__.py	Mon Feb 21 00:37:55 2011 +0100
>> +++ b/mercurial/hgweb/__init__.py	Mon Feb 21 22:15:56 2011 +0000
>> @@ -7,6 +7,7 @@
>>   # GNU General Public License version 2 or any later version.
>>
>>   import os
>> +from mercurial import hg, repo, subrepo, localrepo
>>   import hgweb_mod, hgwebdir_mod
>>
>>   def hgweb(config, name=None, baseui=None):
>> @@ -20,8 +21,27 @@
>>       - list of virtual:real tuples (multi-repo view)
>>       '''
>>
>> -    if ((isinstance(config, str) and not os.path.isdir(config)) or
>> -        isinstance(config, dict) or isinstance(config, list)):
>> +    if isinstance(config, str) and os.path.isdir(config):
>> +        config = hg.repository(baseui, config)
>> +
>> +    if (isinstance(config, repo.repository) and
>> +        '.hgsub' in config.dirstate):
>> +        def srpaths(repo, ctx, ui, vpath):
>> +            paths = [(vpath, repo.root)]
>> +            if '.hgsub' in repo.dirstate:
>> +                for state in subrepo.state(ctx, ui).values():
>> +                    if state[2] != 'hg':
>> +                       continue
>> +                    sr = hg.repository(ui, repo.root + '/' + state[0])
>> +                    if isinstance(sr, localrepo.localrepository):
>> +                        paths.extend(srpaths(sr, sr[state[1]],
>> +                                             ui, vpath + '/' + state[0]))
>> +            return paths
>> +        config = srpaths(config, config[''], baseui,
>> +                         os.path.basename(config.root))
>> +
>> +    if (isinstance(config, str) or isinstance(config, dict) or
>> +        isinstance(config, list)):
>>           # create a multi-dir interface
>>           return hgwebdir_mod.hgwebdir(config, baseui=baseui)
>>       return hgweb_mod.hgweb(config, name=name, baseui=baseui)
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>
>


Mike



More information about the Mercurial-devel mailing list