templatekw: display active bookmark more consistently (issue4552) (BC)
authorRyan McElroy <rmcelroy@fb.com>
Wed, 15 Apr 2015 09:07:54 -0700
changeset 25387 390a10b7843b
parent 25386 a5a95642144b
child 25388 6025cac3d02f
templatekw: display active bookmark more consistently (issue4552) (BC) Previously, the template keyword '{activebookmark}' would only display the active bookmark if it was also pointing to the working directory's parent. Meanwhile, the '{active}' subkeyword of the '{bookmarks}' keyword displays the active bookmark regardless of whether it also points to the working directory's parent. This is confusing. Consider the output of these two templates: $ hg log -T '{activebookmark}\n' -r indent $ hg log -T '{bookmarks % "{bookmark}"}\n' -r indent indent This is the current behavior that can arise after, eg, a pull moves a bookmark out from under you. After this patch, the first template will also return the active bookmark that points to a revision, even if it is not the current parent of the working directory. A test has been added to show the new behavior.
mercurial/templatekw.py
tests/test-bookmarks-current.t
--- a/mercurial/templatekw.py	Sun May 24 18:30:27 2015 +0900
+++ b/mercurial/templatekw.py	Wed Apr 15 09:07:54 2015 -0700
@@ -230,12 +230,9 @@
 def showactivebookmark(**args):
     """:activetbookmark: 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.isactivewdirparent(repo):
-        active = repo._activebookmark
-        if active in args['ctx'].bookmarks():
-            return active
+    active = args['repo']._activebookmark
+    if active and active in args['ctx'].bookmarks():
+        return active
     return ''
 
 def showdate(repo, ctx, templ, **args):
--- a/tests/test-bookmarks-current.t	Sun May 24 18:30:27 2015 +0900
+++ b/tests/test-bookmarks-current.t	Wed Apr 15 09:07:54 2015 -0700
@@ -193,3 +193,12 @@
   $ hg up -q .
   $ test -f .hg/bookmarks.current
   [1]
+
+issue 4552 -- simulate a pull moving the active bookmark
+
+  $ hg up -q X
+  $ printf "Z" > .hg/bookmarks.current
+  $ hg log -T '{activebookmark}\n' -r Z
+  Z
+  $ hg log -T '{bookmarks % "{active}\n"}' -r Z
+  Z