[cig-commits] commit: use util.walkrepos to enumerate nested repositories

Mercurial hg at geodynamics.org
Mon Nov 24 11:26:59 PST 2008


changeset:   33:54ab5a322cac
user:        Robin Farine <robin.farine at terminus.org>
date:        Sun Dec 17 19:56:29 2006 +0100
files:       forest.py
description:
use util.walkrepos to enumerate nested repositories


diff -r 8732cc34aea6 -r 54ab5a322cac forest.py
--- a/forest.py	Sun Dec 17 17:09:27 2006 +0100
+++ b/forest.py	Sun Dec 17 19:56:29 2006 +0100
@@ -51,23 +51,21 @@ def cmd_options(ui, cmd, remove=None):
     return res
 
 
-def enumerate_repos(ui, top=''):
-    """Generate a lexicographically sorted list of repository roots."""
-
-    dirs = ['.']
-    while dirs:
-        root = dirs.pop()
-        entries = os.listdir(os.path.join(top, root))
-        entries.sort()
-        entries.reverse()
-        for e in entries:
-            path = os.path.join(root, e)
-            if not os.path.isdir(os.path.join(top, path)):
-                continue
-            if e == '.hg':
-                yield util.normpath(root)
-            else:
-                dirs.append(path)
+def enumerate_repos(ui, top='.'):
+    """Generate a lexicographically sorted list of repository roots.
+
+    When explicit, top must be a normalized path.
+    """
+
+    res = util.walkrepos(top)
+    pfxlen = len(top + os.sep)
+    res = [p[pfxlen:] for p in res]
+    res.sort()
+    # when the prefix is removed from top itself, it yields the empty string;
+    # let's replace it with '.'
+    res.remove('')
+    res.insert(0, '.')
+    return res
 
 
 def mq_patches_applied(rpath):
@@ -226,9 +224,8 @@ def clone(ui, source, dest, **opts):
             srcpath = source
             destpath = dest
         else:
-            subdir = rpath
-            srcpath = os.path.join(source, subdir)
-            destpath = os.path.join(dest, subdir)
+            srcpath = os.path.join(source, rpath)
+            destpath = os.path.join(dest, rpath)
         if mq_patches_applied(srcpath):
             raise util.Abort(
                 _("'%s' has mq patches applied") % util.pconvert(rpath))



More information about the CIG-COMMITS mailing list