[PATCH 1 of 2 RFC] hgweb: doctest of url creation from wildcard expansion

Mads Kiilerich mads at kiilerich.com
Thu Feb 3 19:51:38 CST 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1296780575 -3600
# Branch stable
# Node ID 822f66da4ec7dc88a21317403e99912a5f0c4dee
# Parent  5fc7c84ed9b0ae9c3b9d16214db147405627d7dd
hgweb: doctest of url creation from wildcard expansion

diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -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
 
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -19,5 +19,8 @@
 import mercurial.util
 doctest.testmod(mercurial.util)
 
+import mercurial.hgweb.hgwebdir_mod
+doctest.testmod(mercurial.hgweb.hgwebdir_mod)
+
 import hgext.convert.cvsps
 doctest.testmod(hgext.convert.cvsps)


More information about the Mercurial-devel mailing list