comparison mercurial/revset.py @ 45750:c00595736595 stable

revset: rename diff(pattern) to diffcontains(pattern) Suggested by Augie, and I think it's better name.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Oct 2020 13:00:04 +0900
parents 99b8b73eb622
children 89a2afe31e82
comparison
equal deleted inserted replaced
45749:f95b16796688 45750:c00595736595
992 dests.__contains__, 992 dests.__contains__,
993 condrepr=lambda: b'<destination %r>' % _sortedb(dests), 993 condrepr=lambda: b'<destination %r>' % _sortedb(dests),
994 ) 994 )
995 995
996 996
997 @predicate(b'diff(pattern)', weight=110) 997 @predicate(b'diffcontains(pattern)', weight=110)
998 def diff(repo, subset, x): 998 def diffcontains(repo, subset, x):
999 """Search revision differences for when the pattern was added or removed. 999 """Search revision differences for when the pattern was added or removed.
1000 1000
1001 The pattern may be a substring literal or a regular expression. See 1001 The pattern may be a substring literal or a regular expression. See
1002 :hg:`help revisions.patterns`. 1002 :hg:`help revisions.patterns`.
1003 """ 1003 """
1004 args = getargsdict(x, b'diff', b'pattern') 1004 args = getargsdict(x, b'diffcontains', b'pattern')
1005 if b'pattern' not in args: 1005 if b'pattern' not in args:
1006 # i18n: "diff" is a keyword 1006 # i18n: "diffcontains" is a keyword
1007 raise error.ParseError(_(b'diff takes at least 1 argument')) 1007 raise error.ParseError(_(b'diffcontains takes at least 1 argument'))
1008 1008
1009 pattern = getstring(args[b'pattern'], _(b'diff requires a string pattern')) 1009 pattern = getstring(
1010 args[b'pattern'], _(b'diffcontains requires a string pattern')
1011 )
1010 regexp = stringutil.substringregexp(pattern, re.M) 1012 regexp = stringutil.substringregexp(pattern, re.M)
1011 1013
1012 # TODO: add support for file pattern and --follow. For example, 1014 # TODO: add support for file pattern and --follow. For example,
1013 # diff(pattern[, set]) where set may be file(pattern) or follow(pattern), 1015 # diffcontains(pattern[, set]) where set may be file(pattern) or
1014 # and we'll eventually add a support for narrowing files by revset? 1016 # follow(pattern), and we'll eventually add a support for narrowing
1017 # files by revset?
1015 fmatch = matchmod.always() 1018 fmatch = matchmod.always()
1016 1019
1017 def makefilematcher(ctx): 1020 def makefilematcher(ctx):
1018 return fmatch 1021 return fmatch
1019 1022
1028 ): 1031 ):
1029 if next(grepmod.difflinestates(pstates, states), None): 1032 if next(grepmod.difflinestates(pstates, states), None):
1030 found = True 1033 found = True
1031 return found 1034 return found
1032 1035
1033 return subset.filter(testdiff, condrepr=(b'<diff %r>', pattern)) 1036 return subset.filter(testdiff, condrepr=(b'<diffcontains %r>', pattern))
1034 1037
1035 1038
1036 @predicate(b'contentdivergent()', safe=True) 1039 @predicate(b'contentdivergent()', safe=True)
1037 def contentdivergent(repo, subset, x): 1040 def contentdivergent(repo, subset, x):
1038 """ 1041 """