Patchwork [2,of,3] revset: stop lowercasing the regex pattern for 'author'

login
register
mail settings
Submitter Matt Harbison
Date Jan. 12, 2017, 5:43 a.m.
Message ID <41eac69037f03733374e.1484199782@Envy>
Download mbox | patch
Permalink /patch/18187/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 12, 2017, 5:43 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1484192530 18000
#      Wed Jan 11 22:42:10 2017 -0500
# Node ID 41eac69037f03733374ea658a6a13de3973860bc
# Parent  73c65ceadc057eab288061b44e18254f674e88c6
revset: stop lowercasing the regex pattern for 'author'

It was probably unintentional for regex, as the meaning of some sequences like
\S and \s is actually inverted by changing the case.  For backward compatibility
however, the matching is forced to case insensitive.
Yuya Nishihara - Jan. 12, 2017, 1:19 p.m.
On Thu, 12 Jan 2017 00:43:02 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1484192530 18000
> #      Wed Jan 11 22:42:10 2017 -0500
> # Node ID 41eac69037f03733374ea658a6a13de3973860bc
> # Parent  73c65ceadc057eab288061b44e18254f674e88c6
> revset: stop lowercasing the regex pattern for 'author'

Queued 1 and 3, thanks.

> -def _substringmatcher(pattern):
> -    kind, pattern, matcher = util.stringmatcher(pattern)
> +def _substringmatcher(pattern, casesensitive=True):
> +    kind, pattern, matcher = util.stringmatcher(pattern,
> +                                                casesensitive=casesensitive)
>      if kind == 'literal':
> -        matcher = lambda s: pattern in s
> +        pattern = encoding.lower(pattern)
> +        matcher = lambda s: pattern in encoding.lower(s)
>      return kind, pattern, matcher

The 'literal' substring match is always case-insensitive though that isn't
a problem right now.

Can you send new version of this?

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -556,9 +556,9 @@ 
     """Alias for ``user(string)``.
     """
     # i18n: "author" is a keyword
-    n = encoding.lower(getstring(x, _("author requires a string")))
-    kind, pattern, matcher = _substringmatcher(n)
-    return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())),
+    n = getstring(x, _("author requires a string"))
+    kind, pattern, matcher = _substringmatcher(n, casesensitive=False)
+    return subset.filter(lambda x: matcher(repo[x].user()),
                          condrepr=('<user %r>', n))
 
 @predicate('bisect(string)', safe=True)
@@ -2246,10 +2246,12 @@ 
 
     return subset.filter(matches, condrepr=('<subrepo %r>', pat))
 
-def _substringmatcher(pattern):
-    kind, pattern, matcher = util.stringmatcher(pattern)
+def _substringmatcher(pattern, casesensitive=True):
+    kind, pattern, matcher = util.stringmatcher(pattern,
+                                                casesensitive=casesensitive)
     if kind == 'literal':
-        matcher = lambda s: pattern in s
+        pattern = encoding.lower(pattern)
+        matcher = lambda s: pattern in encoding.lower(s)
     return kind, pattern, matcher
 
 @predicate('tag([name])', safe=True)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -865,6 +865,17 @@ 
   7
   8
   9
+  $ log 'author(r"re:\S")'
+  0
+  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
   $ log 'branch(é)'
   8
   9