[PATCH] serve: automatically include local subrepos

Matt Mackall mpm at selenic.com
Mon Feb 21 17:51:21 CST 2011


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.

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.

A more acceptable way to do this would be:

- make the single-repo mode of hgweb a special case of hgwebdir
- add a flag to the hgweb scripts to include recursively include
subdirectories by default
- add a command-line switch to 'hg serve' to do the same

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.

> 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


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list