changeset 6284:c93b6c0e6e84

Allow hgwebdir collections to follow symlinks.
author Eric Hopper <hopper@omnifarious.org>
date Sat, 15 Mar 2008 12:42:34 -0700
parents 5a45c82fc7da
children 4b81eecc8aa2
files mercurial/hgweb/hgwebdir_mod.py mercurial/util.py
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 15 22:03:18 2008 -0300
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 15 12:42:34 2008 -0700
@@ -55,7 +55,7 @@
                 self.repos.extend(cleannames(cp.items('paths')))
             if cp.has_section('collections'):
                 for prefix, root in cp.items('collections'):
-                    for path in util.walkrepos(root):
+                    for path in util.walkrepos(root, followsym = True):
                         repo = os.path.normpath(path)
                         name = repo
                         if name.startswith(prefix):
--- a/mercurial/util.py	Sat Mar 15 22:03:18 2008 -0300
+++ b/mercurial/util.py	Sat Mar 15 12:42:34 2008 -0700
@@ -1702,19 +1702,47 @@
     else:
         return "%s..." % (text[:maxlength-3])
 
-def walkrepos(path):
+def walkrepos(path, followsym=False, seen_dirs=None):
     '''yield every hg repository under path, recursively.'''
     def errhandler(err):
         if err.filename == path:
             raise err
+    if followsym and hasattr(os.path, 'samestat'):
+        def _add_dir_if_not_there(dirlst, dirname):
+            match = False
+            samestat = os.path.samestat
+            dirstat = os.stat(dirname)
+            for lstdirstat in dirlst:
+                if samestat(dirstat, lstdirstat):
+                    match = True
+                    break
+            if not match:
+                dirlst.append(dirstat)
+            return not match
+    else:
+        followsym = false
 
-    for root, dirs, files in os.walk(path, onerror=errhandler):
+    if (seen_dirs is None) and followsym:
+        seen_dirs = []
+        _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[:] = [] # 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')):
                 yield qroot # we have a patch queue repo here
+        elif followsym:
+            newdirs = []
+            for d in dirs:
+                fname = os.path.join(root, d)
+                if _add_dir_if_not_there(seen_dirs, fname):
+                    if os.path.islink(fname):
+                        for hgname in walkrepos(fname, True, seen_dirs):
+                            yield hgname
+                    else:
+                        newdirs.append(d)
+            dirs[:] = newdirs
 
 _rcpath = None