[PATCH] walkrepo: recurse only if ** in [paths] or [collections]
Benoit Allard
benoit.allard at gmx.de
Mon Dec 8 15:21:55 CST 2008
# 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/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,20 @@
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.
+ if roottail == '*':
+ recurse = False
+ elif roottail == '**':
+ recurse = True
+ else:
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):
+ for path in util.walkrepos(roothead, followsym=True,
+ recurse=recurse):
path = os.path.normpath(path)
name = util.pconvert(path[len(roothead):]).strip('/')
if prefix:
@@ -68,7 +75,7 @@
self.repos.append((name, path))
if cp.has_section('collections'):
for prefix, root in cp.items('collections'):
- for path in util.walkrepos(root, followsym=True):
+ for path in util.walkrepos(root, followsym=True, recurse=True):
repo = os.path.normpath(path)
name = repo
if name.startswith(prefix):
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):
'''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')):
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 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]
diff -r 8649b2a3de75 -r 3c86853f90c1 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/
diff -r 8649b2a3de75 -r 3c86853f90c1 tests/test-walkrepo.py
--- a/tests/test-walkrepo.py Mon Dec 08 20:42:53 2008 +0100
+++ b/tests/test-walkrepo.py Mon Dec 08 20:43:38 2008 +0100
@@ -28,12 +28,12 @@
def runtest():
reposet = frozenset(walkrepos('.', followsym=True))
- if sym and (len(reposet) != 5):
- print "reposet = %r" % (reposet,)
- print "Found %d repositories when I should have found 5" % (len(reposet),)
- if (not sym) and (len(reposet) != 4):
+ if sym and (len(reposet) != 4):
print "reposet = %r" % (reposet,)
print "Found %d repositories when I should have found 4" % (len(reposet),)
+ if (not sym) and (len(reposet) != 3):
+ print "reposet = %r" % (reposet,)
+ print "Found %d repositories when I should have found 3" % (len(reposet),)
sub1set = frozenset((pjoin('.', 'sub1'),
pjoin('.', 'circle', 'subdir', 'sub1')))
if len(sub1set & reposet) != 1:
More information about the Mercurial-devel
mailing list