##// END OF EJS Templates
revset: add diff(pattern) predicate for "grep --diff"...
Yuya Nishihara -
r46317:99b8b73e default
parent child Browse files
Show More
@@ -17,6 +17,7 b' from . import ('
17 diffutil,
17 diffutil,
18 encoding,
18 encoding,
19 error,
19 error,
20 grep as grepmod,
20 hbisect,
21 hbisect,
21 match as matchmod,
22 match as matchmod,
22 node,
23 node,
@@ -993,6 +994,45 b' def destination(repo, subset, x):'
993 )
994 )
994
995
995
996
997 @predicate(b'diff(pattern)', weight=110)
998 def diff(repo, subset, x):
999 """Search revision differences for when the pattern was added or removed.
1000
1001 The pattern may be a substring literal or a regular expression. See
1002 :hg:`help revisions.patterns`.
1003 """
1004 args = getargsdict(x, b'diff', b'pattern')
1005 if b'pattern' not in args:
1006 # i18n: "diff" is a keyword
1007 raise error.ParseError(_(b'diff takes at least 1 argument'))
1008
1009 pattern = getstring(args[b'pattern'], _(b'diff requires a string pattern'))
1010 regexp = stringutil.substringregexp(pattern, re.M)
1011
1012 # TODO: add support for file pattern and --follow. For example,
1013 # diff(pattern[, set]) where set may be file(pattern) or follow(pattern),
1014 # and we'll eventually add a support for narrowing files by revset?
1015 fmatch = matchmod.always()
1016
1017 def makefilematcher(ctx):
1018 return fmatch
1019
1020 # TODO: search in a windowed way
1021 searcher = grepmod.grepsearcher(repo.ui, repo, regexp, diff=True)
1022
1023 def testdiff(rev):
1024 # consume the generator to discard revfiles/matches cache
1025 found = False
1026 for fn, ctx, pstates, states in searcher.searchfiles(
1027 baseset([rev]), makefilematcher
1028 ):
1029 if next(grepmod.difflinestates(pstates, states), None):
1030 found = True
1031 return found
1032
1033 return subset.filter(testdiff, condrepr=(b'<diff %r>', pattern))
1034
1035
996 @predicate(b'contentdivergent()', safe=True)
1036 @predicate(b'contentdivergent()', safe=True)
997 def contentdivergent(repo, subset, x):
1037 def contentdivergent(repo, subset, x):
998 """
1038 """
@@ -21,6 +21,18 b' pattern error'
21 grep: invalid match pattern: nothing to repeat* (glob)
21 grep: invalid match pattern: nothing to repeat* (glob)
22 [1]
22 [1]
23
23
24 invalid revset syntax
25
26 $ hg log -r 'diff()'
27 hg: parse error: diff takes at least 1 argument
28 [255]
29 $ hg log -r 'diff(:)'
30 hg: parse error: diff requires a string pattern
31 [255]
32 $ hg log -r 'diff("re:**test**")'
33 hg: parse error: invalid regular expression: nothing to repeat* (glob)
34 [255]
35
24 simple
36 simple
25
37
26 $ hg grep -r tip:0 '.*'
38 $ hg grep -r tip:0 '.*'
@@ -553,6 +565,18 b' Test wdir'
553 color:2:-:orange
565 color:2:-:orange
554 color:1:+:orange
566 color:1:+:orange
555
567
568 revset predicate for "grep --diff"
569
570 $ hg log -qr 'diff("re:^bl...$")'
571 0:203191eb5e21
572 $ hg log -qr 'diff("orange")'
573 1:7c585a21e0d1
574 2:11bd8bc8d653
575 3:e0116d3829f8
576 $ hg log -qr '2:0 & diff("orange")'
577 2:11bd8bc8d653
578 1:7c585a21e0d1
579
556 test substring match: '^' should only match at the beginning
580 test substring match: '^' should only match at the beginning
557
581
558 $ hg grep -r tip:0 '^.' --config extensions.color= --color debug
582 $ hg grep -r tip:0 '^.' --config extensions.color= --color debug
General Comments 0
You need to be logged in to leave comments. Login now