Patchwork [1,of,3] templatekw: add 'currentbookmark' keyword to show current bookmark easily

login
register
mail settings
Submitter Katsunori FUJIWARA
Date July 15, 2014, 2:42 p.m.
Message ID <66e93c47d0b3147329da.1405435338@feefifofum>
Download mbox | patch
Permalink /patch/5168/
State Accepted
Commit 2b41ee1b5ea1b2e7dcdd1ba54a28d29624ae76b8
Headers show

Comments

Katsunori FUJIWARA - July 15, 2014, 2:42 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1405434853 -32400
#      Tue Jul 15 23:34:13 2014 +0900
# Node ID 66e93c47d0b3147329da249d419897bd484ab800
# Parent  cf599f8a2da8fc0f0221b0daa3494802eb94af16
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.
Katsunori FUJIWARA - July 15, 2014, 2:48 p.m.
At Tue, 15 Jul 2014 23:42:18 +0900,
FUJIWARA Katsunori wrote:
> 
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1405434853 -32400
> #      Tue Jul 15 23:34:13 2014 +0900
> # Node ID 66e93c47d0b3147329da249d419897bd484ab800
> # Parent  cf599f8a2da8fc0f0221b0daa3494802eb94af16
> templatekw: add 'currentbookmark' keyword to show current bookmark easily

Oops, sorry for missing V2 flag for this posting.

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -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,
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
@@ -1850,6 +1850,15 @@ 
   2 bar* foo 
   1 
   0 
+  $ hg log --template "{rev} {currentbookmark}\n"
+  2 bar
+  1 
+  0 
+  $ hg bookmarks --inactive bar
+  $ hg log --template "{rev} {currentbookmark}\n"
+  2 
+  1 
+  0 
 
 Test stringify on sub expressions