[PATCH 1 of 2] Optionally display chains of empty directories in hgweb manifest view
Ry4an Brase
ry4an-hg at ry4an.org
Fri Oct 17 01:03:57 CDT 2008
# HG changeset patch
# User Ry4an Brase <ry4an-hg at ry4an.org>
# Date 1224223207 18000
# Node ID 2c0d845483b698f34d9de49ad4e92be954703c6c
# Parent 9514cbb6e4f6f54ac8437e7a4eb160a39986a7eb
Optionally display chains of empty directories in hgweb manifest view
diff -r 9514cbb6e4f6 -r 2c0d845483b6 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py Tue Oct 14 20:13:53 2008 +0200
+++ b/mercurial/hgweb/hgweb_mod.py Fri Oct 17 01:00:07 2008 -0500
@@ -67,6 +67,7 @@
self.maxshortchanges = int(self.config("web", "maxshortchanges", 60))
self.maxfiles = int(self.config("web", "maxfiles", 10))
self.allowpull = self.configbool("web", "allowpull", True)
+ self.decendempties = self.configbool("web", "decendempties", False)
self.encoding = self.config("web", "encoding", util._encoding)
def run(self):
diff -r 9514cbb6e4f6 -r 2c0d845483b6 mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py Tue Oct 14 20:13:53 2008 +0200
+++ b/mercurial/hgweb/webcommands.py Fri Oct 17 01:00:07 2008 -0500
@@ -258,6 +258,16 @@
rev = changeset
+def _decendempties(parentpath, hash):
+ if len(hash) == 1:
+ key, val = hash.items().pop()
+ if isinstance(val, dict):
+ name = key + "/"
+ path = parentpath + name
+ return [{"name": name, "path": path}] + _decendempties(path, val)
+ return []
+
+
def manifest(web, req, tmpl):
ctx = webutil.changectx(web.repo, req)
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
@@ -265,6 +275,7 @@
node = ctx.node()
files = {}
+ dirs = {}
parity = paritygen(web.stripecount)
if path and path[-1] != "/":
@@ -276,20 +287,25 @@
if f[:l] != path:
continue
remain = f[l:]
- idx = remain.find('/')
- if idx != -1:
- remain = remain[:idx+1]
- n = None
- files[remain] = (f, n)
+ elements = remain.split('/')
+ if len(elements) == 1:
+ files[remain] = (f, n)
+ elif not web.decendempties:
+ dirs[elements[0]] = {}
+ else:
+ h = dirs
+ for index in range(0, len(elements)-1):
+ if elements[index] not in h:
+ h[elements[index]] = {}
+ h = h[elements[index]]
+ h[None] = 1
- if not files:
+ if not files and not dirs:
raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path)
def filelist(**map):
for f in util.sort(files):
full, fnode = files[f]
- if not fnode:
- continue
fctx = ctx.filectx(full)
yield {"file": full,
@@ -300,14 +316,13 @@
"permissions": mf.flags(full)}
def dirlist(**map):
- for f in util.sort(files):
- full, fnode = files[f]
- if fnode:
- continue
+ for d in util.sort(dirs):
+ path = "%s%s" % (abspath, d)
yield {"parity": parity.next(),
- "path": "%s%s" % (abspath, f),
- "basename": f[:-1]}
+ "path": path,
+ "emptydirs": _decendempties(path + '/', dirs[d]),
+ "basename": d}
return tmpl("manifest",
rev=ctx.rev(),
More information about the Mercurial-devel
mailing list