# HG changeset patch # User Simon King # Date 1338416038 -3600 # Node ID b23bacb230c92f9bf46b44d1b1d6da233bb3b381 # Parent da55d8a77390567b15984da6032963746096bb94 revset: add pattern matching to the 'user' revset expression diff -r da55d8a77390 -r b23bacb230c9 mercurial/revset.py --- 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) diff -r da55d8a77390 -r b23bacb230c9 tests/test-revset.t --- 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