changeset 60:df4e33bd7149

The "forests" request should now be network clean. repo.forests() should always return '/'-separated paths, which will be converted using util.localpath() by the client.
author Simon Law <simon@akoha.org>
date Mon, 27 Aug 2007 13:38:49 -0400
parents 00777c6a37b6
children 45f4c6176e27
files forest.py test-forest test-forest.out
diffstat 3 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/forest.py	Tue Aug 28 15:26:17 2007 -0400
+++ b/forest.py	Mon Aug 27 13:38:49 2007 -0400
@@ -105,32 +105,34 @@
         if err.filename == self.root:
             raise err
 
-    res = []
+    def normpath(path):
+        if path:
+            return util.normpath(path)
+        else:
+            return '.'
+
+    res = {}
     paths = [self.root]
     while paths:
         path = paths.pop()
+        if os.path.realpath(path) in res:
+            continue
         for root, dirs, files in os.walk(path, onerror=errhandler):
             hgdirs = dirs[:]  # Shallow-copy to protect d from dirs.remove() 
             for d in hgdirs:
                 if d == '.hg':
-                    res.append(root)
-                    dirs.remove(d)
+                    res[os.path.realpath(root)] = root
+                    if not walkhg:
+                        dirs.remove(d)
                 else:
                     p = os.path.join(root, d)
-                    if os.path.islink(p):
+                    if os.path.islink(p) and os.path.abspath(p) not in res:
                         paths.append(p)
-    if walkhg:
-        for root in list(res):
-            hgroot = os.path.join(root, '.hg')
-            for e in os.listdir(hgroot):
-                path = os.path.join(hgroot, e)
-                if os.path.isdir(os.path.join(path, '.hg')):
-                    res.append(path)
+    res = res.values()
     res.sort()
     # Turn things into relative paths
     pfx = len(self.root) + 1
-    res = [util.pconvert(os.path.normpath(r[pfx:])) for r in res]
-    return res
+    return [normpath(r[pfx:]) for r in res]
 
 localrepo.localrepository.forests = _localrepo_forests
 
--- a/test-forest	Tue Aug 28 15:26:17 2007 -0400
+++ b/test-forest	Mon Aug 27 13:38:49 2007 -0400
@@ -150,3 +150,12 @@
 echo "walkhg = No" >> walkhg/.hg/hgrc
 hg ftrees -R walkhg --convert
 hg ftrees --cwd walkhg --convert --walkhg=FALSE
+
+echo "# circular trees"
+hg init circular
+hg init circular/a
+ln -s . circular/b
+hg init circular/a/a
+ln -s . circular/a/b
+ln -s .. circular/a/c
+hg fstatus -R circular
--- a/test-forest.out	Tue Aug 28 15:26:17 2007 -0400
+++ b/test-forest.out	Mon Aug 27 13:38:49 2007 -0400
@@ -408,3 +408,13 @@
 a
 .
 a
+# circular trees
+[.]
+? b
+
+[a]
+? b
+? c
+
+[a/a]
+