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

Benoît Allard benoit at aeteurope.nl
Tue Dec 9 08:54:45 CST 2008


Dirkjan Ochtman wrote:
> On Tue, Dec 9, 2008 at 09:44, Ben <benoit.allard at gmx.de> wrote:
>> We're having a political issue there as the release note for 1.1 is
>> mentioning recursive collections. As for now, path = '*' or '**' are
>> behaving recursively, the former could be considered as s bug and
>> corrected into flat discovery. But I'm afraid we'll have to keep the
>> CompatibilityRules on collections.
> 
> Well, I think the slowness for large, checked-out repos is pretty bad,
> so I think that takes precedence. Let's make the recursive walking (a
> nice-to-have feature, but really not a necessary thing IMO) explicitly
> opt-in by requiring ** (which also gives people a chance to move from
> collections to the new-style paths). If we get this into a 1.1.1
> soonish, I think the backwards compatibility damage is minimal; none
> of the large users have switched anyway, and it also means we unbreak
> a lot of people's slowish collections.
> 

I'm fine with this, just wanted to mention it to avoid surprises ...

Next patch integrated your remarks as well as the one from Patrick. I'm 
not quite sure I correctly understood the later though, Patrick if this 
does not correspond, would you email me an updated test-walkrepo which 
highlight your issue ?

# HG changeset patch
# User Benoit Allard <benoit at aeteurope.nl>
# Date 1228765418 -3600
# Node ID 3749436c09e0d4dab9c4cd430add0c417c801abb
# Parent  8649b2a3de75f440fef9fcdf6a5409643d3ff523
walkrepo: recurse only if ** in [paths]

So the behavior is as follow:
collections: one level discovery
paths *: one level discovery (same as collections)
paths **: recursive discovery

the mq repository (if any) is always shown

diff -r 8649b2a3de75 -r 3749436c09e0 mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Dec 08 20:42:53 2008 +0100
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Dec 08 20:43:38 2008 +0100
@@ -54,13 +54,18 @@
                  paths = cleannames(cp.items('paths'))
                  for prefix, root in paths:
                      roothead, roottail = os.path.split(root)
-                    if roottail != '*':
+                    # "foo = /bar/*" makes every subrepo of /bar/ to be
+                    # mounted as foo/subrepo
+                    # and "foo = /bar/**" does even recurse inside the
+                    # subdirectories, remember to use it without 
working dir.
+                    try:
+                        recurse = {'*': False, '**': True}[roottail]
+                    except KeyError:	
                          self.repos.append((prefix, root))
                          continue
-                    # "foo = /bar/*" makes every subrepo of /bar/ to be
-                    # mounted as foo/subrepo
                      roothead = os.path.normpath(roothead)
-                    for path in util.walkrepos(roothead, followsym=True):
+		    repos = util.walkrepos(roothead, followsym=True, recurse=recurse)
+                    for path in repos:
                          path = os.path.normpath(path)
                          name = 
util.pconvert(path[len(roothead):]).strip('/')
                          if prefix:
diff -r 8649b2a3de75 -r 3749436c09e0 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=True):
      '''yield every hg repository under path, recursively.'''
      def errhandler(err):
          if err.filename == path:
@@ -1901,7 +1901,12 @@
          _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:
+                # avoid recursing inside the .hg directory
+		# the mq repository is added in any case
+                dirs.remove('.hg')
+            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')):
diff -r 8649b2a3de75 -r 3749436c09e0 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 init b
  echo b > b/b
@@ -52,6 +53,7 @@
  t/a/=$root/a
  b=$root/b
  coll=$root/*
+rcoll=$root/**
  EOF

  hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \
@@ -70,6 +72,10 @@
  # Test [paths] '*' extension
  "$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/coll/?style=raw'
  "$TESTDIR/get-with-headers.py" localhost:$HGPORT1 
'/coll/a/file/tip/a?style=raw'
+#test [paths] '**' extension
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/rcoll/?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 
'/rcoll/b/d/file/tip/d?style=raw'
+

  cat > collections.conf <<EOF
  [collections]
@@ -85,7 +91,6 @@
  "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 
'/a/file/tip/a?style=raw'
  "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 
'/b/file/tip/b?style=raw'
  "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 
'/c/file/tip/c?style=raw'
-"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/b/d/rev/tip/?style=raw'

  echo % paths errors 1
  cat error-paths-1.log
diff -r 8649b2a3de75 -r 3749436c09e0 tests/test-hgwebdir.out
--- a/tests/test-hgwebdir.out	Mon Dec 08 20:42:53 2008 +0100
+++ b/tests/test-hgwebdir.out	Mon Dec 08 20:43:38 2008 +0100
@@ -31,9 +31,14 @@

  /b/
  /coll/a/
+/coll/a/.hg/patches/
  /coll/b/
-/coll/b/d/
  /coll/c/
+/rcoll/a/
+/rcoll/a/.hg/patches/
+/rcoll/b/
+/rcoll/b/d/
+/rcoll/c/
  /t/a/

  200 Script output follows
@@ -111,18 +116,31 @@


  /coll/a/
+/coll/a/.hg/patches/
  /coll/b/
-/coll/b/d/
  /coll/c/

  200 Script output follows

  a
+200 Script output follows
+
+
+/rcoll/a/
+/rcoll/a/.hg/patches/
+/rcoll/b/
+/rcoll/b/d/
+/rcoll/c/
+
+200 Script output follows
+
+d
  % should succeed
  200 Script output follows


  /a/
+/a/.hg/patches/
  /b/
  /b/d/
  /c/
@@ -136,21 +154,6 @@
  200 Script output follows

  c
-200 Script output follows
-
-
-# HG changeset patch
-# User test
-# Date 0 0
-# Node ID 43cb50608b2ae8635a62e2e8730adefc32a274ee
-
-d
-
---- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/d	Thu Jan 01 00:00:00 1970 +0000
-@@ -0,0 +1,1 @@
-+d
-
  % paths errors 1
  % paths errors 2
  % collections errors
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4197 bytes
Desc: S/MIME Cryptographic Signature
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20081209/415bda72/attachment.bin 


More information about the Mercurial-devel mailing list