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.
--- a/mercurial/commands.py Tue Dec 01 19:23:23 2020 +0900
+++ b/mercurial/commands.py Tue Dec 01 19:32:36 2020 +0900
@@ -4636,12 +4636,6 @@
# 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
--- a/mercurial/logcmdutil.py Tue Dec 01 19:23:23 2020 +0900
+++ b/mercurial/logcmdutil.py Tue Dec 01 19:32:36 2020 +0900
@@ -691,6 +691,7 @@
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 @@
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 @@
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 @@
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)).
--- a/tests/test-log-bookmark.t Tue Dec 01 19:23:23 2020 +0900
+++ b/tests/test-log-bookmark.t Tue Dec 01 19:32:36 2020 +0900
@@ -125,3 +125,68 @@
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]