# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 2020-12-01 10:23:23
# Node ID 9ee791f3278fa466f8a5f066d1d66d41e15dbaca
# Parent  b9ebe0bfed4e619c63e2fbb826aa73e8e0af820e

scmutil: extract function that builds revset expr to select bookmark branch

This is needed to process "log -B" option properly. "log" options have to
be translated to a revset expression, not to an evaluated set.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -2304,7 +2304,13 @@ def bookmarkrevs(repo, mark):
 
     If the bookmarked revision isn't a head, an empty set will be returned.
     """
-    return repo.revs(
+    return repo.revs(format_bookmark_revspec(mark))
+
+
+def format_bookmark_revspec(mark):
+    """Build a revset expression to select revisions reachable by a given
+    bookmark"""
+    return revsetlang.formatspec(
         b"ancestors(bookmark(%s)) - "
         b"ancestors(head() and not bookmark(%s)) - "
         b"ancestors(bookmark() and not bookmark(%s))",