[PATCH 2 of 3 V2] revset: add regular expression support to 'desc'

Matt Harbison mharbison72 at gmail.com
Fri Jan 13 00:24:52 EST 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1483842392 18000
#      Sat Jan 07 21:26:32 2017 -0500
# Node ID 29cbe16c5cccf600fae928df52dbd44171096a6f
# Parent  fd1b7e8e286bad0b3fe529e009c0d4830b25125f
revset: add regular expression support to 'desc'

This is a case insensitive predicate like 'author', so it conforms to the
existing behavior of performing a case insensitive regex.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -814,15 +814,18 @@
 @predicate('desc(string)', safe=True)
 def desc(repo, subset, x):
     """Search commit message for 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 substring that actually starts with `re:`,
+    use the prefix `literal:`.
     """
     # i18n: "desc" is a keyword
-    ds = encoding.lower(getstring(x, _("desc requires a string")))
-
-    def matches(x):
-        c = repo[x]
-        return ds in encoding.lower(c.description())
-
-    return subset.filter(matches, condrepr=('<desc %r>', ds))
+    ds = getstring(x, _("desc requires a string"))
+
+    kind, pattern, matcher = _substringmatcher(ds, casesensitive=False)
+
+    return subset.filter(lambda r: matcher(repo[r].description()),
+                         condrepr=('<desc %r>', ds))
 
 def _descendants(repo, subset, x, followfirst=False):
     roots = getset(repo, fullreposet(repo), x)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -912,6 +912,9 @@
   5
   $ log 'desc(B)'
   5
+  $ hg log -r 'desc(r"re:S?u")' --template "{rev} {desc|firstline}\n"
+  5 5 bug
+  6 6 issue619
   $ log 'descendants(2 or 3)'
   2
   3


More information about the Mercurial-devel mailing list