changeset 981:4f81068ed8cd

Merge with jeffpc
author mpm@selenic.com
date Sat, 20 Aug 2005 13:08:07 -0700
parents a51991ebf229 (current diff) 5197fb9d65d5 (diff)
children 8d2e24bae760
files .hgignore .hgtags MANIFEST.in README contrib/bash_completion doc/hg.1.txt doc/hgrc.5.txt mercurial/bdiff.c mercurial/commands.py mercurial/fancyopts.py mercurial/hg.py mercurial/hgweb.py mercurial/ui.py templates/changelog.tmpl templates/fileannotate.tmpl templates/filelog.tmpl templates/filerevision.tmpl templates/manifest.tmpl templates/map templates/tags.tmpl tests/test-basic.out tests/test-copy.out tests/test-diffdir tests/test-flags.out tests/test-merge-revert2 tests/test-rawcommit1.out tests/test-tag.out tests/test-undo.out tests/test-unrelated-pull.out tests/test-up-local-change tests/test-up-local-change.out tests/test-walk.out
diffstat 7 files changed, 103 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb.py	Sat Aug 20 11:59:10 2005 -0700
+++ b/mercurial/hgweb.py	Sat Aug 20 13:08:07 2005 -0700
@@ -64,25 +64,6 @@
         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 @@
             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 @@
                 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 @@
                 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 @@
                 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 @@
 
         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 @@
                     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 @@
             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 @@
         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",
--- a/templates/changelog.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/changelog.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -18,18 +18,18 @@
 <label for="search1">search:</label>
 <input type="hidden" name="cmd" value="changelog">
 <input name="rev" id="search1" type="text" size="30">
-navigate: <small>#changenav#</small>
+navigate: <small>#changenav%naventry#</small>
 </p>
 </form>
 
-#entries#
+#entries%changelogentry#
 
 <form action="#">
 <p>
 <label for="search2">search:</label>
 <input type="hidden" name="cmd" value="changelog">
 <input name="rev" id="search2" type="text" size="30">
-navigate: <small>#changenav#</small>
+navigate: <small>#changenav%naventry#</small>
 </p>
 </form>
 
--- a/templates/fileannotate.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/fileannotate.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -36,7 +36,7 @@
 <br/>
 
 <table cellspacing="0" cellpadding="0">
-#annotate#
+#annotate%annotateline#
 </table>
 
 #footer#
--- a/templates/filelog.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/filelog.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -16,6 +16,6 @@
 
 <h2>#file# revision history</h2>
 
-#entries#
+#entries%filelogentry#
 
 #footer#
--- a/templates/filerevision.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/filerevision.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -35,7 +35,7 @@
 </table>
 
 <pre>
-#text#
+#text%fileline#
 </pre>
 
 #footer#
--- a/templates/manifest.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/manifest.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -15,6 +15,7 @@
 <tr class="parity1">
   <td><tt>drwxr-xr-x</tt>&nbsp;
   <td><a href="?cmd=manifest;manifest=#manifest#;path=#up#">[up]</a>
-#entries#
+#dentries%manifestdirentry#
+#fentries%manifestfileentry#
 </table>
 #footer#
--- a/templates/tags.tmpl	Sat Aug 20 11:59:10 2005 -0700
+++ b/templates/tags.tmpl	Sat Aug 20 13:08:07 2005 -0700
@@ -11,7 +11,7 @@
 <h2>tags:</h2>
 
 <ul id="tagEntries">
-#entries#
+#entries%tagentry#
 </ul>
 
 #footer#