Patchwork [V2] templatekw: display active bookmark more consistently (issue4552) (BC)

login
register
mail settings
Submitter Ryan McElroy
Date June 1, 2015, 5:43 p.m.
Message ID <acd92991f1b8bf369734.1433180610@devbig105.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9429/
State Accepted
Headers show

Comments

Ryan McElroy - June 1, 2015, 5:43 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1429114074 25200
#      Wed Apr 15 09:07:54 2015 -0700
# Node ID acd92991f1b8bf36973457a9fca28897655ef4f9
# Parent  4cc3fb23881d9abc7745501ef0d777e5976ddb52
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.
Pierre-Yves David - June 1, 2015, 6:14 p.m.
On 06/01/2015 10:43 AM, Ryan McElroy wrote:
> # HG changeset patch
> # User Ryan McElroy <rmcelroy@fb.com>
> # Date 1429114074 25200
> #      Wed Apr 15 09:07:54 2015 -0700
> # Node ID acd92991f1b8bf36973457a9fca28897655ef4f9
> # Parent  4cc3fb23881d9abc7745501ef0d777e5976ddb52
> templatekw: display active bookmark more consistently (issue4552) (BC)

pushed to the clowncopter, thank, make a lot more sense.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -230,12 +230,9 @@  def showcurrentbookmark(**args):
 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):
diff --git a/tests/test-bookmarks-current.t b/tests/test-bookmarks-current.t
--- a/tests/test-bookmarks-current.t
+++ b/tests/test-bookmarks-current.t
@@ -193,3 +193,12 @@  analogous to hg book -i <active bookmark
   $ hg up -q .
   $ test -f .hg/bookmarks.current
   [1]
+
+issue 4552 -- simulate a pull moving the active bookmark
+
+  $ hg up -q X
+  $ echo -n Z > .hg/bookmarks.current
+  $ hg log -T '{activebookmark}\n' -r Z
+  Z
+  $ hg log -T '{bookmarks % "{active}\n"}' -r Z
+  Z