diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -994,24 +994,27 @@ def destination(repo, subset, x): ) -@predicate(b'diff(pattern)', weight=110) -def diff(repo, subset, x): +@predicate(b'diffcontains(pattern)', weight=110) +def diffcontains(repo, subset, x): """Search revision differences for when the pattern was added or removed. The pattern may be a substring literal or a regular expression. See :hg:`help revisions.patterns`. """ - args = getargsdict(x, b'diff', b'pattern') + args = getargsdict(x, b'diffcontains', b'pattern') if b'pattern' not in args: - # i18n: "diff" is a keyword - raise error.ParseError(_(b'diff takes at least 1 argument')) - - pattern = getstring(args[b'pattern'], _(b'diff requires a string pattern')) + # i18n: "diffcontains" is a keyword + raise error.ParseError(_(b'diffcontains takes at least 1 argument')) + + pattern = getstring( + args[b'pattern'], _(b'diffcontains requires a string pattern') + ) regexp = stringutil.substringregexp(pattern, re.M) # TODO: add support for file pattern and --follow. For example, - # diff(pattern[, set]) where set may be file(pattern) or follow(pattern), - # and we'll eventually add a support for narrowing files by revset? + # diffcontains(pattern[, set]) where set may be file(pattern) or + # follow(pattern), and we'll eventually add a support for narrowing + # files by revset? fmatch = matchmod.always() def makefilematcher(ctx): @@ -1030,7 +1033,7 @@ def diff(repo, subset, x): found = True return found - return subset.filter(testdiff, condrepr=(b'', pattern)) + return subset.filter(testdiff, condrepr=(b'', pattern)) @predicate(b'contentdivergent()', safe=True) diff --git a/tests/test-grep.t b/tests/test-grep.t --- a/tests/test-grep.t +++ b/tests/test-grep.t @@ -23,13 +23,13 @@ pattern error invalid revset syntax - $ hg log -r 'diff()' - hg: parse error: diff takes at least 1 argument + $ hg log -r 'diffcontains()' + hg: parse error: diffcontains takes at least 1 argument [255] - $ hg log -r 'diff(:)' - hg: parse error: diff requires a string pattern + $ hg log -r 'diffcontains(:)' + hg: parse error: diffcontains requires a string pattern [255] - $ hg log -r 'diff("re:**test**")' + $ hg log -r 'diffcontains("re:**test**")' hg: parse error: invalid regular expression: nothing to repeat* (glob) [255] @@ -567,13 +567,13 @@ Test wdir revset predicate for "grep --diff" - $ hg log -qr 'diff("re:^bl...$")' + $ hg log -qr 'diffcontains("re:^bl...$")' 0:203191eb5e21 - $ hg log -qr 'diff("orange")' + $ hg log -qr 'diffcontains("orange")' 1:7c585a21e0d1 2:11bd8bc8d653 3:e0116d3829f8 - $ hg log -qr '2:0 & diff("orange")' + $ hg log -qr '2:0 & diffcontains("orange")' 2:11bd8bc8d653 1:7c585a21e0d1