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

login
register
mail settings
Submitter Antonio Zanardo
Date Feb. 4, 2013, 3:56 p.m.
Message ID <c4dd3efdf2246f8d8081.1359993369@air.local>
Download mbox | patch
Permalink /patch/799/
State Rejected, archived
Delegated to: Matt Mackall
Headers show

Comments

Antonio Zanardo - Feb. 4, 2013, 3:56 p.m.
# HG changeset patch
# User Antonio Zanardo <zanardo@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).
Matt Mackall - Feb. 10, 2013, 4:43 p.m.
On Mon, 2013-02-04 at 13:56 -0200, Antonio Zanardo wrote:
> # HG changeset patch
> # User Antonio Zanardo <zanardo@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.

Huh, so what is the current state here?

It appears that we:
- list all branch heads
- sort by open vs closed
- sort by rev
- display open / closed / inactive

This is.. unfortunate. We should probably not show closed branches at
all and we've long considered active/inactive to be a meaningless and
outdated concept (starting the day we introduced closed branches).

We should instead:

- list only open branch heads
- sort by rev

This can in fact be done today purely in templates, with something like:

{ifeq(status, 'closed', '', '{branch}....'}

And we can have separate lists using something like the above as well.
Perhaps an on-click method to show closed branches would be better than
a session variable.

Patch

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())