# HG changeset patch # User Mads Kiilerich # Date 2011-02-15 00:04:10 # Node ID f947d9a4c45c89e669a7bfc1912520a3368efd0d # Parent 12773f1b7728f0bfdd564fff1800ed99a40b3a6b 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 @@ def findrepos(paths): 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 @@ -22,5 +22,8 @@ doctest.testmod(mercurial.util) import mercurial.encoding doctest.testmod(mercurial.encoding) +import mercurial.hgweb.hgwebdir_mod +doctest.testmod(mercurial.hgweb.hgwebdir_mod) + import hgext.convert.cvsps doctest.testmod(hgext.convert.cvsps)