[PATCH] color: enable branches support

Brodie Rao brodie at bitheap.org
Tue Aug 17 18:02:36 CDT 2010


# HG changeset patch
# User Jeremy Whitlock <jcscoobyrs at gmail.com>
# Date 1280379903 21600
# Node ID 7317d18eb21b30e7df61ab0ebf73f360de3a065b
# Parent  60bfb876dc4545d5e1742e401d376c4f7f2e2d4b
color: enable branches support

This commit updates the branches command to use ui.label for the branch names
and the changeset.  This implementation allows assigning colors to the four
states of a branch: active, closed, current and inactive.  While you can
configure color for the four states, only current and closed have default colors
of green and black bold respectively.

diff -r 60bfb876dc45 -r 7317d18eb21b hgext/color.py
--- a/hgext/color.py	Tue Aug 17 17:44:19 2010 -0500
+++ b/hgext/color.py	Wed Jul 28 23:05:03 2010 -0600
@@ -62,6 +62,11 @@ Default effects may be overridden from t
 
   bookmarks.current = green
 
+  branches.active = none
+  branches.closed = black bold
+  branches.current = green
+  branches.inactive = none
+
 The color extension will try to detect whether to use ANSI codes or
 Win32 console APIs, unless it is made explicit::
 
@@ -87,6 +92,10 @@ _effects = {'none': 0, 'black': 30, 'red
             'cyan_background': 46, 'white_background': 47}
 
 _styles = {'grep.match': 'red bold',
+           'branches.active': 'none',
+           'branches.closed': 'black bold',
+           'branches.current': 'green',
+           'branches.inactive': 'none',
            'diff.changed': 'white',
            'diff.deleted': 'red',
            'diff.diffline': 'bold',
diff -r 60bfb876dc45 -r 7317d18eb21b mercurial/commands.py
--- a/mercurial/commands.py	Tue Aug 17 17:44:19 2010 -0500
+++ b/mercurial/commands.py	Wed Jul 28 23:05:03 2010 -0600
@@ -512,16 +512,22 @@ def branches(ui, repo, active=False, clo
             else:
                 hn = repo.lookup(node)
                 if isactive:
+                    label = 'branches.active'
                     notice = ''
                 elif hn not in repo.branchheads(tag, closed=False):
                     if not closed:
                         continue
+                    label = 'branches.closed'
                     notice = _(' (closed)')
                 else:
+                    label = 'branches.inactive'
                     notice = _(' (inactive)')
+                if tag == repo.dirstate.branch():
+                    label = 'branches.current'
                 rev = str(node).rjust(31 - encoding.colwidth(encodedtag))
-                data = encodedtag, rev, hexfunc(hn), notice
-                ui.write("%s %s:%s%s\n" % data)
+                rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset')
+                encodedtag = ui.label(encodedtag, label)
+                ui.write("%s %s%s\n" % (encodedtag, rev, notice))
 
 def bundle(ui, repo, fname, dest=None, **opts):
     """create a changegroup file
diff -r 60bfb876dc45 -r 7317d18eb21b tests/test-branches.t
--- a/tests/test-branches.t	Tue Aug 17 17:44:19 2010 -0500
+++ b/tests/test-branches.t	Wed Jul 28 23:05:03 2010 -0600
@@ -341,3 +341,53 @@ branch b
   date:        Thu Jan 01 00:00:09 1970 +0000
   summary:     prune bad branch
   
+default branch colors:
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "color =" >> $HGRCPATH
+
+  $ hg up -C c
+  3 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg commit -d '9 0' --close-branch -m 'reclosing this branch'
+  $ hg up -C b
+  2 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ hg branches --color=always
+  b                             13:6ac12926b8c3
+  a branch name much longer than the default justification used by branches 7:10ff5895aa57
+  a                              5:d8cbc61dbaa6 (inactive)
+  default                        0:19709c5a4e75 (inactive)
+
+default closed branch color:
+
+  $ hg branches --color=always --closed
+  b                             13:6ac12926b8c3
+  a branch name much longer than the default justification used by branches 7:10ff5895aa57
+  c                             14:717d2e6fabe1 (closed)
+  a                              5:d8cbc61dbaa6 (inactive)
+  default                        0:19709c5a4e75 (inactive)
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "color =" >> $HGRCPATH
+  $ echo "[color]" >> $HGRCPATH
+  $ echo "branches.active = green" >> $HGRCPATH
+  $ echo "branches.closed = blue" >> $HGRCPATH
+  $ echo "branches.current = red" >> $HGRCPATH
+  $ echo "branches.inactive = magenta" >> $HGRCPATH
+  $ echo "log.changeset = cyan" >> $HGRCPATH
+
+custom branch colors:
+
+  $ hg branches --color=always
+  b                             13:6ac12926b8c3
+  a branch name much longer than the default justification used by branches 7:10ff5895aa57
+  a                              5:d8cbc61dbaa6 (inactive)
+  default                        0:19709c5a4e75 (inactive)
+
+custom closed branch color:
+
+  $ hg branches --color=always --closed
+  b                             13:6ac12926b8c3
+  a branch name much longer than the default justification used by branches 7:10ff5895aa57
+  c                             14:717d2e6fabe1 (closed)
+  a                              5:d8cbc61dbaa6 (inactive)
+  default                        0:19709c5a4e75 (inactive)


More information about the Mercurial-devel mailing list