[PATCH] walkrepo: recurse only if ** in [paths] or [collections]

Patrick Mézard pmezard at gmail.com
Mon Dec 8 16:48:39 CST 2008


Benoit Allard a écrit :
> # HG changeset patch
> # User Benoit Allard <benoit at aeteurope.nl>
> # Date 1228765418 -3600
> # Node ID 3c86853f90c13e2b0a0433f6b29d183c68fc22a3
> # Parent  8649b2a3de75f440fef9fcdf6a5409643d3ff523
> walkrepo: recurse only if ** in [paths] or [collections]
> 
> So the behavior is as follow:
> collections: recursive discovery
> paths *: one level discovery
> paths **: recursive discovery (same as collections)
> 
> the mq repository (if any) is always shown

[...] 

> diff -r 8649b2a3de75 -r 3c86853f90c1 mercurial/util.py
> --- a/mercurial/util.py	Mon Dec 08 20:42:53 2008 +0100
> +++ b/mercurial/util.py	Mon Dec 08 20:43:38 2008 +0100
> @@ -1876,7 +1876,7 @@
>      else:
>          return "%s..." % (text[:maxlength-3])
>  
> -def walkrepos(path, followsym=False, seen_dirs=None):
> +def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):

Any reason to change the default behaviour ? I suppose that without this you do not have to change test-walkrepo.py. Plus it breaks the recursive behaviour wrt symlinks.

>      '''yield every hg repository under path, recursively.'''
>      def errhandler(err):
>          if err.filename == path:
> @@ -1901,7 +1901,10 @@
>          _add_dir_if_not_there(seen_dirs, path)
>      for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler):
>          if '.hg' in dirs:
> -            dirs.remove('.hg') # don't recurse inside the .hg directory
> +            if recurse:
> +                dirs.remove('.hg') # don't recurse inside the .hg directory
> +            else:
> +                dirs[:] = [] # don't descend further
>              yield root # found a repository
>              qroot = os.path.join(root, '.hg', 'patches')
>              if os.path.isdir(os.path.join(qroot, '.hg')):

This change looks a bit misleading to me. What it does is "do not recurse within Mercurial repositories" whereas my intuitive understanding is "do not recurse at all". Also, there is something to do with symlinks, at least propagate the "recurse" flag. If I have a directory layout like:

root/repo1/.hg
          /subrepo1/.hg
    /link_to_repo2 -> repo2/.hg
                           /subrepo2.hg
                           /link_to_repo3 ...
    /link_to_dir -> dir/repo4/.hg

I feel like recurse=False should discover repo1 and repo2 but none of the others. If "root" is itself a repository, I don't really know what should happen, probably discover only "root" for simplicity. I may be missing important use cases though. This logic makes the code more complex since you must be able to tell the first call from recursive call, for in the former you are likely to discover children entries and not in the latter.

> diff -r 8649b2a3de75 -r 3c86853f90c1 tests/test-hgwebdir
> --- a/tests/test-hgwebdir	Mon Dec 08 20:42:53 2008 +0100
> +++ b/tests/test-hgwebdir	Mon Dec 08 20:43:38 2008 +0100
> @@ -8,6 +8,7 @@
>  hg init a
>  echo a > a/a
>  hg --cwd a ci -Ama -d'1 0'
> +hg --cwd a qinit --config extensions.hgext.mq= -c

hg --cwd a qinit -c ?

--
Patrick Mézard


More information about the Mercurial-devel mailing list