[PATCH] hgweb: Added directory browsing support when the descend setting is set to a false value
Paul Boddie
paul.boddie at biotek.uio.no
Mon Sep 6 06:45:50 CDT 2010
# HG changeset patch
# User Paul Boddie <paul at boddie.org.uk>
# Date 1283717736 -7200
# Node ID 3db11696610d4c6109751655fe4e98766bc3cdf7
# Parent 74f54b7775f2fac7283f6f674822da0145e18dd1
Added directory browsing support when the descend setting is set to a false value.
diff -r 74f54b7775f2 -r 3db11696610d mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py Mon Sep 06 07:14:18 2010 +0200
+++ b/mercurial/hgweb/hgwebdir_mod.py Sun Sep 05 22:15:36 2010 +0200
@@ -200,28 +200,30 @@
def rawentries(subdir="", **map):
descend = self.ui.configbool('web', 'descend', True)
+ seen = set()
for name, path in self.repos:
if not name.startswith(subdir):
continue
name = name[len(subdir):]
- if not descend and '/' in name:
- continue
- u = self.ui.copy()
- try:
- u.readconfig(os.path.join(path, '.hg', 'hgrc'))
- except Exception, e:
- u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
- continue
- def get(section, name, default=None):
- return u.config(section, name, default, untrusted=True)
+ # identify directories containing repositories
+ directory = not descend and '/' in name
+ if directory:
+ nameparts = name.split('/')
+ name = nameparts[0]
- if u.configbool("web", "hidden", untrusted=True):
- continue
+ # skip already seen directories
+ if name in seen:
+ continue
+ else:
+ seen.add(name)
- if not self.read_allowed(u, req):
- continue
+ # 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:
@@ -230,30 +232,64 @@
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)
- except error.RepoError:
- u.warn(_('error accessing repository at %s\n') % path)
- continue
- try:
- d = (get_mtime(r.spath), util.makedate()[1])
- except OSError:
- continue
+ # 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
- contact = get_contact(get)
- description = get("web", "description", "")
- name = get("web", "name", name)
- row = dict(contact=contact or "unknown",
- contact_sort=contact.upper() or "unknown",
- name=name,
- name_sort=name,
- url=url,
- description=description or "unknown",
- description_sort=description.upper() or "unknown",
- lastchange=d,
- lastchange_sort=d[1]-d[0],
- archives=archivelist(u, "tip", url))
+ row = dict(contact="",
+ contact_sort="",
+ name=name,
+ name_sort=name,
+ url=url,
+ description="",
+ description_sort="",
+ lastchange=d,
+ lastchange_sort=d[1]-d[0],
+ archives=[])
+ else:
+ u = self.ui.copy()
+ try:
+ u.readconfig(os.path.join(path, '.hg', 'hgrc'))
+ except Exception, e:
+ u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e))
+ continue
+ def get(section, name, default=None):
+ return u.config(section, name, default, untrusted=True)
+
+ if u.configbool("web", "hidden", untrusted=True):
+ continue
+
+ if not self.read_allowed(u, req):
+ continue
+
+ # update time with local timezone
+ try:
+ r = hg.repository(self.ui, path)
+ except error.RepoError:
+ u.warn(_('error accessing repository at %s\n') % path)
+ continue
+ try:
+ d = (get_mtime(r.spath), util.makedate()[1])
+ except OSError:
+ continue
+
+ contact = get_contact(get)
+ description = get("web", "description", "")
+ name = get("web", "name", name)
+ row = dict(contact=contact or "unknown",
+ contact_sort=contact.upper() or "unknown",
+ name=name,
+ name_sort=name,
+ url=url,
+ description=description or "unknown",
+ description_sort=description.upper() or "unknown",
+ lastchange=d,
+ lastchange_sort=d[1]-d[0],
+ archives=archivelist(u, "tip", url))
yield row
sortdefault = None, False
More information about the Mercurial-devel
mailing list