# HG changeset patch # User Matt Harbison # Date 1483842392 18000 # Node ID 931a60880df4713e0f03270eac319185c0af2e01 # Parent db38cfc7c29d0979f33bd2eeaae544cc73f608b0 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 -r db38cfc7c29d -r 931a60880df4 mercurial/revset.py --- a/mercurial/revset.py Wed Jan 11 22:42:10 2017 -0500 +++ b/mercurial/revset.py Sat Jan 07 21:26:32 2017 -0500 @@ -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=('', 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=('', ds)) def _descendants(repo, subset, x, followfirst=False): roots = getset(repo, fullreposet(repo), x) diff -r db38cfc7c29d -r 931a60880df4 tests/test-revset.t --- a/tests/test-revset.t Wed Jan 11 22:42:10 2017 -0500 +++ b/tests/test-revset.t Sat Jan 07 21:26:32 2017 -0500 @@ -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