##// END OF EJS Templates
grep: add stub class that maintains cache and states of grep operation...
Yuya Nishihara -
r46289:494642ed default
parent child Browse files
Show More
@@ -3398,9 +3398,11 b' def grep(ui, repo, pattern, *pats, **opt'
3398 if opts.get(b'print0'):
3398 if opts.get(b'print0'):
3399 sep = eol = b'\0'
3399 sep = eol = b'\0'
3400
3400
3401 getfile = util.lrucachefunc(repo.file)
3401 searcher = grepmod.grepsearcher(ui, repo, regexp)
3402 matches = {}
3402
3403 copies = {}
3403 getfile = searcher._getfile
3404 matches = searcher._matches
3405 copies = searcher._copies
3404
3406
3405 def grepbody(fn, rev, body):
3407 def grepbody(fn, rev, body):
3406 matches[rev].setdefault(fn, [])
3408 matches[rev].setdefault(fn, [])
@@ -3520,12 +3522,12 b' def grep(ui, repo, pattern, *pats, **opt'
3520 fm.data(matched=False)
3522 fm.data(matched=False)
3521 fm.end()
3523 fm.end()
3522
3524
3523 skip = set()
3525 skip = searcher._skip
3524 revfiles = {}
3526 revfiles = searcher._revfiles
3525 found = False
3527 found = False
3526 follow = opts.get(b'follow')
3528 follow = opts.get(b'follow')
3527
3529
3528 getrenamed = scmutil.getrenamedfn(repo)
3530 getrenamed = searcher._getrenamed
3529
3531
3530 def readfile(ctx, fn):
3532 def readfile(ctx, fn):
3531 rev = ctx.rev()
3533 rev = ctx.rev()
@@ -9,7 +9,11 b' from __future__ import absolute_import'
9
9
10 import difflib
10 import difflib
11
11
12 from . import pycompat
12 from . import (
13 pycompat,
14 scmutil,
15 util,
16 )
13
17
14
18
15 def matchlines(body, regexp):
19 def matchlines(body, regexp):
@@ -69,3 +73,20 b' def difflinestates(a, b):'
69 yield (b'-', a[i])
73 yield (b'-', a[i])
70 for i in pycompat.xrange(blo, bhi):
74 for i in pycompat.xrange(blo, bhi):
71 yield (b'+', b[i])
75 yield (b'+', b[i])
76
77
78 class grepsearcher(object):
79 """Search files and revisions for lines matching the given pattern"""
80
81 def __init__(self, ui, repo, regexp):
82 self._ui = ui
83 self._repo = repo
84 self._regexp = regexp
85
86 self._getfile = util.lrucachefunc(repo.file)
87 self._getrenamed = scmutil.getrenamedfn(repo)
88
89 self._matches = {}
90 self._copies = {}
91 self._skip = set()
92 self._revfiles = {}
General Comments 0
You need to be logged in to leave comments. Login now