[PATCH 5 of 6 v4] revset: add pattern matching to the 'user' revset expression
Simon King
simon at simonking.org.uk
Wed May 30 18:36:18 CDT 2012
# HG changeset patch
# User Simon King <simon at simonking.org.uk>
# Date 1338416038 -3600
# Node ID fc8c4e6bb44a2d8d12929d3a0361e0923c057ec8
# Parent d4a095917864002af4fc691c59ffd8522b065d31
revset: add pattern matching to the 'user' revset expression
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -279,7 +279,8 @@
"""
# i18n: "author" is a keyword
n = encoding.lower(getstring(x, _("author requires a string")))
- return [r for r in subset if n in encoding.lower(repo[r].user())]
+ kind, pattern, matcher = _substringmatcher(n)
+ return [r for r in subset if matcher(encoding.lower(repo[r].user()))]
def bisect(repo, subset, x):
"""``bisect(string)``
@@ -1188,6 +1189,11 @@
pattern = pattern[8:]
return 'literal', pattern, pattern.__eq__
+def _substringmatcher(pattern):
+ kind, pattern, matcher = _stringmatcher(pattern)
+ if kind == 'literal':
+ matcher = lambda s: pattern in s
+ return kind, pattern, matcher
def tag(repo, subset, x):
"""``tag([name])``
@@ -1219,6 +1225,10 @@
def user(repo, subset, x):
"""``user(string)``
User name contains string. The match is case-insensitive.
+
+ If `string` starts with `re:`, the remainder of the string is treated as
+ a regular expression. To match a user that actually contains `re:`, use
+ the prefix `literal:`.
"""
return author(repo, subset, x)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -230,6 +230,17 @@
5
$ log 'author(bob)'
2
+ $ log 'author("re:bob|test")'
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
$ log 'branch(é)'
8
9
More information about the Mercurial-devel
mailing list