revset: add pattern matching to the 'user' revset expression
authorSimon King <simon@simonking.org.uk>
Wed, 30 May 2012 23:13:58 +0100
changeset 16823 b23bacb230c9
parent 16822 da55d8a77390
child 16824 f3b8c82a559c
revset: add pattern matching to the 'user' revset expression
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Wed May 30 23:13:33 2012 +0100
+++ b/mercurial/revset.py	Wed May 30 23:13:58 2012 +0100
@@ -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)
 
--- a/tests/test-revset.t	Wed May 30 23:13:33 2012 +0100
+++ b/tests/test-revset.t	Wed May 30 23:13:58 2012 +0100
@@ -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