[cig-commits] commit: filesystem vs mercurial path representation

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


changeset:   32:8732cc34aea6
user:        Robin Farine <robin.farine at terminus.org>
date:        Sun Dec 17 17:09:27 2006 +0100
files:       forest.py test-forest
description:
filesystem vs mercurial path representation


diff -r bfb2a805b490 -r 8732cc34aea6 forest.py
--- a/forest.py	Sun Dec 17 15:34:50 2006 +0100
+++ b/forest.py	Sun Dec 17 17:09:27 2006 +0100
@@ -4,6 +4,13 @@
 #
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
+
+# Repository path representation
+#
+# Repository paths stored in the filesystem representation are stored
+# in variables named 'rpath'. Repository roots in the mercurial
+# representation, stored in variables named 'root', are used in
+# snapshot files and in command output.
 
 """Operations on trees with nested Mercurial repositories.
 
@@ -63,11 +70,11 @@ def enumerate_repos(ui, top=''):
                 dirs.append(path)
 
 
-def mq_patches_applied(rootpath):
-    rootpath = os.path.join(rootpath, ".hg")
-    entries = os.listdir(rootpath)
+def mq_patches_applied(rpath):
+    rpath = os.path.join(rpath, ".hg")
+    entries = os.listdir(rpath)
     for e in entries:
-        path = os.path.join(rootpath, e)
+        path = os.path.join(rpath, e)
         if e == "data" or not os.path.isdir(path):
             continue
         series = os.path.join(path, "series")
@@ -78,13 +85,14 @@ def mq_patches_applied(rootpath):
                 return True
     return False
 
-def repository(ui, root):
-    while os.path.islink(root):
-        path = os.readlink(root)
+
+def repository(ui, rpath):
+    while os.path.islink(rpath):
+        path = os.readlink(rpath)
         if not os.path.isabs(path):
-            path = os.path.join(os.path.dirname(root), path)
-        root = path
-    return hg.repository(ui, root)
+            path = os.path.join(os.path.dirname(rpath), path)
+        rpath = path
+    return hg.repository(ui, rpath)
 
 
 class ForestSnapshot(object):
@@ -154,7 +162,7 @@ class ForestSnapshot(object):
                 repo = toprepo
             else:
                 try:
-                    repo = repository(ui, root)
+                    repo = repository(ui, util.localpath(root))
                 except RepoError:
                     ui.write(_("skipped, no valid repo found\n\n"))
                     continue
@@ -177,11 +185,12 @@ class ForestSnapshot(object):
 
         rootmap = {}
         self.trees = []
-        for root in enumerate_repos(ui):
-            if mq_patches_applied(root):
+        for rpath in enumerate_repos(ui):
+            root = util.pconvert(rpath)
+            if mq_patches_applied(rpath):
                 raise util.Abort(_("'%s' has mq patches applied") % root)
-            if root != '.':
-                repo = repository(ui, root)
+            if rpath != '.':
+                repo = repository(ui, rpath)
             if opts['tip']:
                 rev = 'tip'
             else:
@@ -212,22 +221,23 @@ def clone(ui, source, dest, **opts):
     dest = os.path.normpath(dest)
     opts['rev'] = []
     roots = []
-    for root in enumerate_repos(ui, source):
-        if root == '.':
+    for rpath in enumerate_repos(ui, source):
+        if rpath == '.':
             srcpath = source
             destpath = dest
         else:
-            subdir = util.localpath(root)
+            subdir = rpath
             srcpath = os.path.join(source, subdir)
             destpath = os.path.join(dest, subdir)
         if mq_patches_applied(srcpath):
-            raise util.Abort(_("'%s' has mq patches applied") % root)
-        roots.append((root, srcpath, destpath))
+            raise util.Abort(
+                _("'%s' has mq patches applied") % util.pconvert(rpath))
+        roots.append((rpath, srcpath, destpath))
     for root in roots:
         destpfx = os.path.dirname(root[2])
         if destpfx and not os.path.exists(destpfx):
             os.makedirs(destpfx)
-        ui.write("[%s]\n" % root[0])
+        ui.write("[%s]\n" % util.pconvert(root[0]))
         commands.clone(ui, root[1], root[2], **opts)
         ui.write("\n")
 
@@ -327,12 +337,12 @@ def status(ui, repo, *pats, **opts):
 def status(ui, repo, *pats, **opts):
     """Display the status of a forest of working directories."""
 
-    for root in enumerate_repos(ui):
+    for rpath in enumerate_repos(ui):
         mqflag = ""
-        if mq_patches_applied(root):
+        if mq_patches_applied(rpath):
             mqflag = " *mq*"
-        ui.write("[%s]%s\n" % (root, mqflag))
-        repo = repository(ui, root)
+        ui.write("[%s]%s\n" % (util.pconvert(rpath), mqflag))
+        repo = repository(ui, rpath)
         commands.status(repo.ui, repo, *pats, **opts)
         ui.write("\n")
 
@@ -340,8 +350,12 @@ def trees(ui, *unused, **opts):
 def trees(ui, *unused, **opts):
     """List the roots of the repositories."""
 
-    for root in enumerate_repos(ui, ''):
-        ui.write(root + '\n')
+    if opts['convert']:
+        l = [util.pconvert(p) for p in enumerate_repos(ui)]
+    else:
+        l = enumerate_repos(ui)
+    for t in l:
+        ui.write(t + '\n')
 
 
 def uisetup(ui):
@@ -371,12 +385,14 @@ def uisetup(ui):
             (snapshot,
              [('t', 'tip', None,
                _("record tip instead of actual child revisions"))],
-             'hg fsnap [OPTIONS] [SNAPSHOT-FILE]'),
+             _('hg fsnap [OPTIONS] [SNAPSHOT-FILE]')),
         "fstatus" :
             (status,
              cmd_options(ui, 'status'),
              _('hg fstatus [OPTIONS]')),
         "ftrees" :
-            (trees, '',
-             'hg ftrees [OPTIONS]'),
+            (trees,
+             [('c', 'convert', None,
+               _("convert paths to mercurial representation"))],
+             _('hg ftrees [OPTIONS]'))
         }
diff -r bfb2a805b490 -r 8732cc34aea6 test-forest
--- a/test-forest	Sun Dec 17 15:34:50 2006 +0100
+++ b/test-forest	Sun Dec 17 17:09:27 2006 +0100
@@ -25,7 +25,7 @@ hg commit --cwd toplevel/t/t -A -m "star
 hg commit --cwd toplevel/t/t -A -m "start" -d "0 0"
 
 echo "# ftrees"
-hg ftrees --cwd toplevel
+hg ftrees --convert --cwd toplevel
 
 echo "# fstatus"
 echo "x" >> toplevel/d/d/t/f



More information about the CIG-COMMITS mailing list