[PATCH 2 of 5 v2] revset: add pattern matching to 'branch' revset expression
Simon King
simon at simonking.org.uk
Sat May 26 19:06:38 CDT 2012
# HG changeset patch
# User Simon King <simon at simonking.org.uk>
# Date 1338074344 -3600
# Node ID 011d34e5304ba13f722d306d3045a7713adb2b6d
# Parent 379f9cd195c0c31bae73e7d317db4bb22d0c9cc3
revset: add pattern matching to 'branch' revset expression
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -325,14 +325,25 @@
"""``branch(string or set)``
All changesets belonging to the given branch or the branches of the given
changesets.
+
+ If `string` starts with `re:`, the remainder of the name is treated as
+ a regular expression. To match a branch that actually starts with `re:`,
+ use the prefix `literal:`.
"""
try:
b = getstring(x, '')
- if b in repo.branchmap():
- return [r for r in subset if repo[r].branch() == b]
except error.ParseError:
# not a string, but another revspec, e.g. tip()
pass
+ else:
+ kind, pattern, matcher = _stringmatcher(b)
+ if kind == 'literal':
+ # note: falls through to the revspec case if no branch with
+ # this name exists
+ if pattern in repo.branchmap():
+ return [r for r in subset if matcher(repo[r].branch())]
+ else:
+ return [r for r in subset if matcher(repo[r].branch())]
s = getset(repo, range(len(repo)), x)
b = set()
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -233,6 +233,16 @@
$ log 'branch(é)'
8
9
+ $ log 'branch(a)'
+ 0
+ $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n'
+ 0 a
+ 2 a-b-c-
+ 3 +a+b+c+
+ 4 -a-b-c-
+ 5 /a/b/c/
+ 6 _a_b_c_
+ 7 .a.b.c.
$ log 'children(ancestor(4,5))'
2
3
More information about the Mercurial-devel
mailing list