[PATCH 1 of 2] hgweb: make 'branches' template split branches by status

Antonio Zanardo zanardo at gmail.com
Mon Feb 4 09:56:09 CST 2013


# HG changeset patch
# User Antonio Zanardo <zanardo at gmail.com>
# Date 1359989550 7200
# Node ID c4dd3efdf2246f8d80813ea84d7c9f0b45eb046c
# Parent  7068089c95a2ff3c1b536bbb52ca6bc1f06fc06e
hgweb: make 'branches' template split branches by status

This is the initial work on webcommands.py branches() to allow hgweb templates
to split branches list by status or entirely hide closed branches, for example.

The 'entries' function was not modified and the original behavior of returning
all branches was kept so we do not break existent templates.

There are two new functions to be used by templates:

- entriesopen: returns all open (and inactive) branches.

- entriesclosed: returns by default the first 10 closed branches. When the
  session variable allclosed is used, all closed branches are returned.

The entriesopen do not split open branches (ie, with heads) and inactive
branches (ie, without heads) because splitting those lists on templates *should*
confuse users (IMHO).

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -449,8 +449,20 @@
     heads = web.repo.heads()
     parity = paritygen(web.stripecount)
     sortkey = lambda ctx: (not ctx.closesbranch(), ctx.rev())
+    allclosedvars = copy.copy(tmpl.defaults['sessionvars'])
+    allclosedvars['allclosed'] = 1
 
-    def entries(limit, **map):
+    allclosed = False
+    if 'allclosed' in req.form:
+        allclosed = True
+
+    def entries(limit, filterstatus=None, **map):
+        # When the session variable 'allclosed' is not active,
+        # lets limit the number of closed branches to 10, when
+        # requested by entriesclosed()
+        if not allclosed:
+            if filterstatus and 'closed' in filterstatus:
+                limit = 10
         count = 0
         if not tips:
             for t, n in web.repo.branchtags().iteritems():
@@ -458,22 +470,28 @@
         for ctx in sorted(tips, key=sortkey, reverse=True):
             if limit > 0 and count >= limit:
                 return
-            count += 1
             if not web.repo.branchheads(ctx.branch()):
                 status = 'closed'
             elif ctx.node() not in heads:
                 status = 'inactive'
             else:
                 status = 'open'
-            yield {'parity': parity.next(),
-                   'branch': ctx.branch(),
-                   'status': status,
-                   'node': ctx.hex(),
-                   'date': ctx.date()}
+            if not filterstatus or status in filterstatus:
+                count += 1
+                yield {'parity': parity.next(),
+                       'branch': ctx.branch(),
+                       'status': status,
+                       'node': ctx.hex(),
+                       'date': ctx.date()}
 
     return tmpl('branches', node=hex(web.repo.changelog.tip()),
                 entries=lambda **x: entries(0, **x),
-                latestentry=lambda **x: entries(1, **x))
+                entriesclosed=lambda **x:
+                    entries(0, filterstatus=('closed'), **x),
+                entriesopen=lambda **x:
+                    entries(0, filterstatus=('open', 'inactive'), **x),
+                latestentry=lambda **x: entries(1, **x),
+                allclosedvars=allclosedvars)
 
 def summary(web, req, tmpl):
     i = reversed(web.repo.tagslist())


More information about the Mercurial-devel mailing list