[PATCH 3 of 3 V2] template: add 'current' to scope during {bookmarks % ...}

Durham Goode durham at fb.com
Fri Feb 14 14:23:57 CST 2014


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1392183633 28800
#      Tue Feb 11 21:40:33 2014 -0800
# Node ID 6958dd4c11c6f8929a955b3c468e39dea1f11cc8
# Parent  c30dc74862faaf6e4a5a701799506b4dcfe0697b
template: add 'current' to scope during {bookmarks % ...}

This adds the keyword 'current' to the template scope when processing a
bookmark list. The 'current' keyword resolves to the name of the currently
active bookmark in the repo. This allows us to apply special labels to the
current bookmark to distinguish it (especially in the case where there are
multiple bookmarks on the same commit).

Example: "{bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}"

Results in a space separated list of bookmarks where the current bookmark has
an asterix.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -195,8 +195,12 @@
     """:bookmarks: List of strings. Any bookmarks associated with the
     changeset.
     """
+    repo = args['ctx']._repo
     bookmarks = args['ctx'].bookmarks()
-    return showlist('bookmark', bookmarks, **args)
+    hybrid = showlist('bookmark', bookmarks, **args)
+    for value in hybrid.values:
+        value['current'] = repo._bookmarkcurrent
+    return hybrid
 
 def showchildren(**args):
     """:children: List of strings. The children of the changeset."""
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -1676,3 +1676,10 @@
   Rev: 0
   Ancestor: 0
   
+Test current bookmark templating
+
+  $ hg book foo
+  $ hg book bar
+  $ hg log --template "{rev} {bookmarks % '{bookmark}{ifeq(bookmark, current, \"*\")} '}\n"
+  1 bar* foo 
+  0 


More information about the Mercurial-devel mailing list