diff mercurial/hgweb/hgwebdir_mod.py @ 13402:f947d9a4c45c

hgweb: doctest of url creation from wildcard expansion
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 15 Feb 2011 01:04:10 +0100
parents 5bcb6c9d16db
children 8ed91088acbb
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Feb 14 18:04:20 2011 -0600
+++ b/mercurial/hgweb/hgwebdir_mod.py	Tue Feb 15 01:04:10 2011 +0100
@@ -33,14 +33,25 @@
             repos.append((prefix, root))
             continue
         roothead = os.path.normpath(os.path.abspath(roothead))
-        for path in util.walkrepos(roothead, followsym=True, recurse=recurse):
-            path = os.path.normpath(path)
-            name = util.pconvert(path[len(roothead):]).strip('/')
-            if prefix:
-                name = prefix + '/' + name
-            repos.append((name, path))
+        paths = util.walkrepos(roothead, followsym=True, recurse=recurse)
+        repos.extend(urlrepos(prefix, roothead, paths))
     return repos
 
+def urlrepos(prefix, roothead, paths):
+    """yield url paths and filesystem paths from a list of repo paths
+
+    >>> list(urlrepos('hg', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
+    [('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg/', '/opt')]
+    >>> list(urlrepos('', '/opt', ['/opt/r', '/opt/r/r', '/opt']))
+    [('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')]
+    """
+    for path in paths:
+        path = os.path.normpath(path)
+        name = util.pconvert(path[len(roothead):]).strip('/')
+        if prefix:
+            name = prefix + '/' + name
+        yield name, path
+
 class hgwebdir(object):
     refreshinterval = 20