Patchwork [5,of,5,V2] branches: include active, closed and current flags in template output

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 3, 2014, 2:02 p.m.
Message ID <67b89f1c9df06038be14.1412344929@mimosa>
Download mbox | patch
Permalink /patch/6093/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 3, 2014, 2:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1412259962 -32400
#      Thu Oct 02 23:26:02 2014 +0900
# Node ID 67b89f1c9df06038be14bc3e1aaf42de75c838aa
# Parent  95ff932dfcb2f649470a617951a76bea8f02d53e
branches: include active, closed and current flags in template output
Matt Mackall - Oct. 3, 2014, 5:04 p.m.
On Fri, 2014-10-03 at 23:02 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1412259962 -32400
> #      Thu Oct 02 23:26:02 2014 +0900
> # Node ID 67b89f1c9df06038be14bc3e1aaf42de75c838aa
> # Parent  95ff932dfcb2f649470a617951a76bea8f02d53e
> branches: include active, closed and current flags in template output

These are queued for default, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1116,7 +1116,8 @@  def branches(ui, repo, active=False, clo
         else:
             label = 'branches.inactive'
             notice = _(' (inactive)')
-        if tag == repo.dirstate.branch():
+        current = (tag == repo.dirstate.branch())
+        if current:
             label = 'branches.current'
 
         fm.startitem()
@@ -1126,6 +1127,7 @@  def branches(ui, repo, active=False, clo
         fmt = ' ' * padsize + ' %d:%s'
         fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()),
                      label='log.changeset changeset.%s' % ctx.phasestr())
+        fm.data(active=isactive, closed=not isopen, current=current)
         if not ui.quiet:
             fm.plain(notice)
         fm.plain('\n')
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -475,27 +475,42 @@  template output:
   $ hg branches -Tjson --closed
   [
    {
+    "active": true,
     "branch": "b",
+    "closed": false,
+    "current": true,
     "node": "e23b5505d1ad24aab6f84fd8c7cb8cd8e5e93be0",
     "rev": 13
    },
    {
+    "active": true,
     "branch": "a branch name much longer than the default justification used by branches",
+    "closed": false,
+    "current": false,
     "node": "10ff5895aa5793bd378da574af8cec8ea408d831",
     "rev": 7
    },
    {
+    "active": false,
     "branch": "c",
+    "closed": true,
+    "current": false,
     "node": "f894c25619d3f1484639d81be950e0a07bc6f1f6",
     "rev": 14
    },
    {
+    "active": false,
     "branch": "a",
+    "closed": false,
+    "current": false,
     "node": "d8cbc61dbaa6dc817175d1e301eecb863f280832",
     "rev": 5
    },
    {
+    "active": false,
     "branch": "default",
+    "closed": false,
+    "current": false,
     "node": "19709c5a4e75bf938f8e349aff97438539bb729e",
     "rev": 0
    }