Patchwork [3,of,4] log: do not override other filtering and sorting options by --bookmark

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 1, 2020, 12:50 p.m.
Message ID <773cf7f8899449979131.1606827033@lemosa>
Download mbox | patch
Permalink /patch/47756/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 1, 2020, 12:50 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1606818756 -32400
#      Tue Dec 01 19:32:36 2020 +0900
# Node ID 773cf7f8899449979131792e82a49fc6bc0d25ec
# Parent  3b3f53b5b57f32b10c6e5c8aacffab002fd793ea
log: do not override other filtering and sorting options by --bookmark

This basically reimplements 0aa118f18d4b 'log: add bookmark option to
"hg log"'. Before, any other filtering options but --rev were ignored.
-G didn't work either since the ordering constraint wasn't enforced.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4636,12 +4636,6 @@  def log(ui, repo, *pats, **opts):
         # then filter the result by logcmdutil._makerevset() and --limit
         revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts)
 
-    if opts.get(b'bookmark'):
-        cmdutil.check_at_most_one_arg(opts, b'rev', b'bookmark')
-        bookmarks = opts.get(b'bookmark')
-        bookmark = bookmarks[0]
-        revs, differ = logcmdutil.get_bookmark_revs(repo, bookmark, walk_opts)
-
     getcopies = None
     if opts.get(b'copies'):
         endrev = None
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -691,6 +691,7 @@  class walkopts(object):
     revspec = attr.ib()  # type: List[bytes]
 
     # miscellaneous queries to filter revisions (see "hg help log" for details)
+    bookmarks = attr.ib(default=attr.Factory(list))  # type: List[bytes]
     branches = attr.ib(default=attr.Factory(list))  # type: List[bytes]
     date = attr.ib(default=None)  # type: Optional[bytes]
     keywords = attr.ib(default=attr.Factory(list))  # type: List[bytes]
@@ -746,6 +747,7 @@  def parseopts(ui, pats, opts):
         pats=pats,
         opts=opts,
         revspec=opts.get(b'rev', []),
+        bookmarks=opts.get(b'bookmark', []),
         # branch and only_branch are really aliases and must be handled at
         # the same time
         branches=opts.get(b'branch', []) + opts.get(b'only_branch', []),
@@ -937,6 +939,14 @@  def _makerevset(repo, wopts, slowpath):
                 val = [revsetlang.formatspec(revop, v) for v in val]
             expr.append(revsetlang.formatspec(listop, val))
 
+    if wopts.bookmarks:
+        expr.append(
+            revsetlang.formatspec(
+                b'%lr',
+                [scmutil.format_bookmark_revspec(v) for v in wopts.bookmarks],
+            )
+        )
+
     if expr:
         expr = b'(' + b' and '.join(expr) + b')'
     else:
@@ -1023,26 +1033,6 @@  def getrevs(repo, wopts):
     return revs, differ
 
 
-def get_bookmark_revs(repo, bookmark, walk_opts):
-    # type: (Any, bookmark, walk_opts) -> Tuple[smartset.abstractsmartset, Optional[changesetdiffer]]
-    """Return (revs, differ) where revs is a smartset
-
-    differ is a changesetdiffer with pre-configured file matcher.
-    """
-    revs, filematcher = makewalker(repo, walk_opts)
-    if not revs:
-        return revs, None
-    differ = changesetdiffer()
-    differ._makefilematcher = filematcher
-
-    if bookmark:
-        if bookmark not in repo._bookmarks:
-            raise error.Abort(_(b"bookmark '%s' not found") % bookmark)
-        revs = scmutil.bookmarkrevs(repo, bookmark)
-
-    return revs, differ
-
-
 def _parselinerangeopt(repo, opts):
     """Parse --line-range log option and return a list of tuples (filename,
     (fromline, toline)).
diff --git a/tests/test-log-bookmark.t b/tests/test-log-bookmark.t
--- a/tests/test-log-bookmark.t
+++ b/tests/test-log-bookmark.t
@@ -125,3 +125,68 @@  Check the log of topic X, topic Y, and d
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     Add foo in 'default'
   
+
+Set up multiple bookmarked heads:
+
+  $ hg bookmark merged-head
+  $ hg up 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  (leaving bookmark merged-head)
+  $ echo "Z" > z.txt
+  $ hg ci -Am 'Add Z'
+  adding z.txt
+  $ hg bookmark topic-Z
+
+  $ hg log -GT '{rev}: {branch}, {bookmarks}\n'
+  @  5: sebhtml, topic-Z
+  |
+  | o  4: default, merged-head
+  |/|
+  | o    3: default,
+  | |\
+  | | o  2: sebhtml, sebhtml/99992-topic-Y
+  | |/
+  o |  1: sebhtml, sebhtml/99991-topic-X
+  |/
+  o  0: default,
+  
+
+Multiple revisions under bookmarked head:
+
+  $ hg log -GT '{rev}: {branch}, {bookmarks}\n' -B merged-head
+  o    4: default, merged-head
+  |\
+  | ~
+  o    3: default,
+  |\
+  ~ ~
+
+Follows multiple bookmarks:
+
+  $ hg log -GT '{rev}: {branch}, {bookmarks}\n' -B merged-head -B topic-Z
+  @  5: sebhtml, topic-Z
+  |
+  ~
+  o    4: default, merged-head
+  |\
+  | ~
+  o    3: default,
+  |\
+  ~ ~
+
+Filter by bookmark and branch:
+
+  $ hg log -GT '{rev}: {branch}, {bookmarks}\n' -B merged-head -B topic-Z -b default
+  o    4: default, merged-head
+  |\
+  | ~
+  o    3: default,
+  |\
+  ~ ~
+
+
+Unknown bookmark:
+
+  $ hg log -B unknown
+  abort: bookmark 'unknown' does not exist
+  [255]