Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/hgwebdir_mod.py @ 16239:287f76b3f502
hgweb: support multi-level repository indexes by enabling descend and collapse
The descend option in hgweb can be used to display all reachable repositories
within a directory hierarchy if set to True. However, all reachable
repositories, regardless of their depth below the root of the hierarchy, are
then listed at the same level - expanded - in the hgweb interface. This patch
adds support for showing only each level of a directory hierarchy, with
subrepositories being shown alongside their parent repositories only at the
appropriate level (because there is no way to navigate to subrepositories from
within repositories), and the contents of directories hidden - collapsed -
behind a link for each directory. To enable this multi-level navigation, a new
option called collapse must be set to True when the descend option is set to
True.
author | Paul Boddie <paul@boddie.org.uk> |
---|---|
date | Sat, 18 Feb 2012 20:10:19 +0100 |
parents | a31b8e03af28 |
children | d94c470c3deb |
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py Tue Mar 06 18:43:05 2012 +0200 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Feb 18 20:10:19 2012 +0100 @@ -245,12 +245,67 @@ def rawentries(subdir="", **map): descend = self.ui.configbool('web', 'descend', True) + collapse = self.ui.configbool('web', 'collapse', False) + seenrepos = set() + seendirs = set() for name, path in self.repos: if not name.startswith(subdir): continue name = name[len(subdir):] - if not descend and '/' in name: + directory = False + + if '/' in name: + if not descend: + continue + + nameparts = name.split('/') + rootname = nameparts[0] + + if not collapse: + pass + elif rootname in seendirs: + continue + elif rootname in seenrepos: + pass + else: + directory = True + name = rootname + + # redefine the path to refer to the directory + discarded = '/'.join(nameparts[1:]) + + # remove name parts plus accompanying slash + path = path[:-len(discarded) - 1] + + parts = [name] + if 'PATH_INFO' in req.env: + parts.insert(0, req.env['PATH_INFO'].rstrip('/')) + if req.env['SCRIPT_NAME']: + parts.insert(0, req.env['SCRIPT_NAME']) + url = re.sub(r'/+', '/', '/'.join(parts) + '/') + + # show either a directory entry or a repository + if directory: + # get the directory's time information + try: + d = (get_mtime(path), util.makedate()[1]) + except OSError: + continue + + row = dict(contact="", + contact_sort="", + name=name, + name_sort=name, + url=url, + description="", + description_sort="", + lastchange=d, + lastchange_sort=d[1]-d[0], + archives=[]) + + seendirs.add(name) + yield row continue u = self.ui.copy() @@ -268,13 +323,6 @@ if not self.read_allowed(u, req): continue - parts = [name] - if 'PATH_INFO' in req.env: - parts.insert(0, req.env['PATH_INFO'].rstrip('/')) - if req.env['SCRIPT_NAME']: - parts.insert(0, req.env['SCRIPT_NAME']) - url = re.sub(r'/+', '/', '/'.join(parts) + '/') - # update time with local timezone try: r = hg.repository(self.ui, path) @@ -302,6 +350,8 @@ lastchange=d, lastchange_sort=d[1]-d[0], archives=archivelist(u, "tip", url)) + + seenrepos.add(name) yield row sortdefault = None, False