Mercurial > public > mercurial-scm > hg-stable
diff mercurial/grep.py @ 45697:494642ed3c50
grep: add stub class that maintains cache and states of grep operation
Prepares for extracting stateful functions from commands.grep().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 09 Sep 2020 15:56:40 +0900 |
parents | de6f2afc0247 |
children | 41e0cbccb260 |
line wrap: on
line diff
--- a/mercurial/grep.py Wed Sep 09 15:23:49 2020 +0900 +++ b/mercurial/grep.py Wed Sep 09 15:56:40 2020 +0900 @@ -9,7 +9,11 @@ import difflib -from . import pycompat +from . import ( + pycompat, + scmutil, + util, +) def matchlines(body, regexp): @@ -69,3 +73,20 @@ yield (b'-', a[i]) for i in pycompat.xrange(blo, bhi): yield (b'+', b[i]) + + +class grepsearcher(object): + """Search files and revisions for lines matching the given pattern""" + + def __init__(self, ui, repo, regexp): + self._ui = ui + self._repo = repo + self._regexp = regexp + + self._getfile = util.lrucachefunc(repo.file) + self._getrenamed = scmutil.getrenamedfn(repo) + + self._matches = {} + self._copies = {} + self._skip = set() + self._revfiles = {}