diff mercurial/templatekw.py @ 21896:2b41ee1b5ea1

templatekw: add 'currentbookmark' keyword to show current bookmark easily Before this patch, complicated template expression below is required to show current active bookmark if it is associated with the changeset. "{bookmarks % '{ifeq(bookmark, current, \"{bookmark}\")}'}" This patch add 'currentbookmark' keyword to show current bookmark easily.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Jul 2014 23:34:13 +0900
parents 6cb419dd3703
children 764adc332f6e
line wrap: on
line diff
--- a/mercurial/templatekw.py	Wed Jul 16 14:53:03 2014 -0700
+++ b/mercurial/templatekw.py	Tue Jul 15 23:34:13 2014 +0900
@@ -208,6 +208,17 @@
     childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
     return showlist('children', childrevs, element='child', **args)
 
+def showcurrentbookmark(**args):
+    """:currentbookmark: String. The active bookmark, if it is
+    associated with the changeset"""
+    import bookmarks as bookmarks # to avoid circular import issues
+    repo = args['repo']
+    if bookmarks.iscurrent(repo):
+        current = repo._bookmarkcurrent
+        if current in args['ctx'].bookmarks():
+            return current
+    return ''
+
 def showdate(repo, ctx, templ, **args):
     """:date: Date information. The date when the changeset was committed."""
     return ctx.date()
@@ -364,6 +375,7 @@
     'branches': showbranches,
     'bookmarks': showbookmarks,
     'children': showchildren,
+    'currentbookmark': showcurrentbookmark,
     'date': showdate,
     'desc': showdescription,
     'diffstat': showdiffstat,