diff --git a/mercurial/hgweb.py b/mercurial/hgweb.py --- a/mercurial/hgweb.py +++ b/mercurial/hgweb.py @@ -64,25 +64,6 @@ def write(*things): else: sys.stdout.write(str(thing)) -def template(tmpl, filters = {}, **map): - while tmpl: - m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl) - if m: - yield tmpl[:m.start(0)] - v = map.get(m.group(1), "") - v = callable(v) and v(**map) or v - - fl = m.group(2) - if fl: - for f in fl.split("|")[1:]: - v = filters[f](v) - - yield v - tmpl = tmpl[m.end(0):] - else: - yield tmpl - return - class templater: def __init__(self, mapfile, filters = {}, defaults = {}): self.cache = {} @@ -109,7 +90,37 @@ class templater: tmpl = self.cache[t] except KeyError: tmpl = self.cache[t] = file(self.map[t]).read() - return template(tmpl, self.filters, **m) + return self.template(tmpl, self.filters, **m) + + def template(self, tmpl, filters = {}, **map): + while tmpl: + m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl) + if m: + yield tmpl[:m.start(0)] + v = map.get(m.group(1), "") + v = callable(v) and v(**map) or v + + format = m.group(2) + fl = m.group(4) + + if format: + q = v.__iter__ + for i in q(): + lm = map.copy() + lm.update(i) + yield self(format[1:], **lm) + + v = "" + + elif fl: + for f in fl.split("|")[1:]: + v = filters[f](v) + + yield v + tmpl = tmpl[m.end(0):] + else: + yield tmpl + return def rfc822date(x): return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) @@ -242,12 +253,12 @@ class hgweb: if pos + f < count: l.append(("+" + r, pos + f)) if pos - f >= 0: l.insert(0, ("-" + r, pos - f)) - yield self.t("naventry", rev = 0, label="(0)") + yield {"rev": 0, "label": "(0)"} for label, rev in l: - yield self.t("naventry", label = label, rev = rev) + yield {"label": label, "rev": rev} - yield self.t("naventry", label="tip") + yield {"label": "tip", "rev": ""} def changelist(**map): parity = (start - end) & 1 @@ -259,22 +270,21 @@ class hgweb: hn = hex(n) t = float(changes[2].split(' ')[0]) - l.insert(0, self.t( - 'changelogentry', - parity = parity, - author = changes[1], - parent = self.parents("changelogparent", + l.insert(0, { + "parity": parity, + "author": changes[1], + "parent": self.parents("changelogparent", cl.parents(n), cl.rev), - changelogtag = self.showtag("changelogtag",n), - manifest = hex(changes[0]), - desc = changes[4], - date = t, - files = self.listfilediffs(changes[3], n), - rev = i, - node = hn)) + "changelogtag": self.showtag("changelogtag",n), + "manifest": hex(changes[0]), + "desc": changes[4], + "date": t, + "files": self.listfilediffs(changes[3], n), + "rev": i, + "node": hn}) parity = 1 - parity - yield l + for e in l: yield e cl = self.repo.changelog mf = cl.read(cl.tip())[0] @@ -389,20 +399,19 @@ class hgweb: cs = cl.read(cl.node(lr)) t = float(cs[2].split(' ')[0]) - l.insert(0, self.t("filelogentry", - parity = parity, - filenode = hex(n), - filerev = i, - file = f, - node = hex(cn), - author = cs[1], - date = t, - parent = self.parents("filelogparent", + l.insert(0, {"parity": parity, + "filenode": hex(n), + "filerev": i, + "file": f, + "node": hex(cn), + "author": cs[1], + "date": t, + "parent": self.parents("filelogparent", fl.parents(n), fl.rev, file=f), - desc = cs[4])) + "desc": cs[4]}) parity = 1 - parity - yield l + for e in l: yield e yield self.t("filelog", file = f, @@ -422,9 +431,9 @@ class hgweb: def lines(): for l, t in enumerate(text.splitlines(1)): - yield self.t("fileline", line = t, - linenumber = "% 6d" % (l + 1), - parity = l & 1) + yield {"line": t, + "linenumber": "% 6d" % (l + 1), + "parity": l & 1} yield self.t("filerevision", file = f, filenode = node, @@ -478,13 +487,12 @@ class hgweb: parity = 1 - parity last = cnode - yield self.t("annotateline", - parity = parity, - node = hex(cnode), - rev = r, - author = name, - file = f, - line = l) + yield {"parity": parity, + "node": hex(cnode), + "rev": r, + "author": name, + "file": f, + "line": l} yield self.t("fileannotate", file = f, @@ -528,28 +536,40 @@ class hgweb: fl.sort() for f in fl: full, fnode = files[f] - if fnode: - yield self.t("manifestfileentry", - file = full, - manifest = mnode, - filenode = hex(fnode), - parity = parity, - basename = f, - permissions = mff[full]) - else: - yield self.t("manifestdirentry", - parity = parity, - path = os.path.join(path, f), - manifest = mnode, basename = f[:-1]) + if not fnode: + continue + + yield {"file": full, + "manifest": mnode, + "filenode": hex(fnode), + "parity": parity, + "basename": f, + "permissions": mff[full]} parity = 1 - parity + def dirlist(**map): + parity = 0 + fl = files.keys() + fl.sort() + for f in fl: + full, fnode = files[f] + if fnode: + continue + + yield {"parity": parity, + "path": os.path.join(path, f), + "manifest": mnode, + "basename": f[:-1]} + parity = 1 - parity + yield self.t("manifest", manifest = mnode, rev = rev, node = hex(node), path = path, up = up(path), - entries = filelist) + fentries = filelist, + dentries = dirlist) def tags(self): cl = self.repo.changelog @@ -561,10 +581,9 @@ class hgweb: def entries(**map): parity = 0 for k,n in i: - yield self.t("tagentry", - parity = parity, - tag = k, - node = hex(n)) + yield {"parity": parity, + "tag": k, + "node": hex(n)} parity = 1 - parity yield self.t("tags", diff --git a/templates/changelog.tmpl b/templates/changelog.tmpl --- a/templates/changelog.tmpl +++ b/templates/changelog.tmpl @@ -18,18 +18,18 @@ -navigate: #changenav# +navigate: #changenav%naventry#

-#entries# +#entries%changelogentry#

-navigate: #changenav# +navigate: #changenav%naventry#

diff --git a/templates/fileannotate.tmpl b/templates/fileannotate.tmpl --- a/templates/fileannotate.tmpl +++ b/templates/fileannotate.tmpl @@ -36,7 +36,7 @@
-#annotate# +#annotate%annotateline#
#footer# diff --git a/templates/filelog.tmpl b/templates/filelog.tmpl --- a/templates/filelog.tmpl +++ b/templates/filelog.tmpl @@ -16,6 +16,6 @@

#file# revision history

-#entries# +#entries%filelogentry# #footer# diff --git a/templates/filerevision.tmpl b/templates/filerevision.tmpl --- a/templates/filerevision.tmpl +++ b/templates/filerevision.tmpl @@ -35,7 +35,7 @@
-#text#
+#text%fileline#
 
#footer# diff --git a/templates/manifest.tmpl b/templates/manifest.tmpl --- a/templates/manifest.tmpl +++ b/templates/manifest.tmpl @@ -15,6 +15,7 @@ drwxr-xr-x  [up] -#entries# +#dentries%manifestdirentry# +#fentries%manifestfileentry# #footer# diff --git a/templates/tags.tmpl b/templates/tags.tmpl --- a/templates/tags.tmpl +++ b/templates/tags.tmpl @@ -11,7 +11,7 @@

tags:

#footer#