Patchwork [1,of,2] revset: expand bookmark(.) to the active bookmark

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 25, 2018, 11:56 a.m.
Message ID <d3e265cb2ff891c7b7a7.1535198166@mimosa>
Download mbox | patch
Permalink /patch/34045/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 25, 2018, 11:56 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1535195788 -32400
#      Sat Aug 25 20:16:28 2018 +0900
# Node ID d3e265cb2ff891c7b7a7779399017c69fee0aef7
# Parent  337443f09fc8e565f7063f5132109e9a2bc7fa96
revset: expand bookmark(.) to the active bookmark

We do that in several places. I'm not pretty sure if "literal:." should be
expanded or not, so it's disabled for now.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -454,6 +454,8 @@  def bookmark(repo, subset, x):
         kind, pattern, matcher = stringutil.stringmatcher(bm)
         bms = set()
         if kind == 'literal':
+            if bm == pattern:
+                pattern = repo._bookmarks.expandname(pattern)
             bmrev = repo._bookmarks.get(pattern, None)
             if not bmrev:
                 raise error.RepoLookupError(_("bookmark '%s' does not exist")
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -151,6 +151,34 @@  bookmarks revset
   summary:     0
   
 
+"." is expanded to the active bookmark:
+
+  $ hg log -r 'bookmark(.)'
+  changeset:   1:925d80f479bb
+  bookmark:    X2
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     1
+  
+
+but "literal:." is not since "." seems not a literal bookmark:
+
+  $ hg log -r 'bookmark("literal:.")'
+  abort: bookmark '.' does not exist!
+  [255]
+
+"." should fail if there's no active bookmark:
+
+  $ hg bookmark --inactive
+  $ hg log -r 'bookmark(.)'
+  abort: no active bookmark
+  [255]
+BUG: this should be resolved to an empty set:
+  $ hg log -r 'present(bookmark(.))'
+  abort: no active bookmark
+  [255]
+
   $ hg log -r 'bookmark(unknown)'
   abort: bookmark 'unknown' does not exist!
   [255]
@@ -166,6 +194,12 @@  bookmarks revset
   $ hg help revsets | grep 'bookmark('
       "bookmark([name])"
 
+reactivate "X2"
+
+  $ hg update X2
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (activating bookmark X2)
+
 bookmarks X and X2 moved to rev 1, Y at rev -1
 
   $ hg bookmarks