comparison mercurial/grep.py @ 45721:f9d3ff23bfc0

grep: extract main search loop as searcher method Still displayer part is in commands.grep(), the core grep logic is now reusable. I'll revisit the displayer stuff later since it will be another long series.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 09 Sep 2020 17:17:38 +0900
parents c10c87c8fe79
children d4ba4d51f85f
comparison
equal deleted inserted replaced
45720:508dfd1c18df 45721:f9d3ff23bfc0
112 from future search""" 112 from future search"""
113 copy = self._copies.get(rev, {}).get(fn) 113 copy = self._copies.get(rev, {}).get(fn)
114 self._skip.add(fn) 114 self._skip.add(fn)
115 if copy: 115 if copy:
116 self._skip.add(copy) 116 self._skip.add(copy)
117
118 def searchfiles(self, revs, makefilematcher):
119 """Walk files and revisions to yield (fn, ctx, pstates, states)
120 matches
121
122 states is a list of linestate objects. pstates may be empty unless
123 diff is True.
124 """
125 for ctx in scmutil.walkchangerevs(
126 self._repo, revs, makefilematcher, self._prep
127 ):
128 rev = ctx.rev()
129 parent = ctx.p1().rev()
130 for fn in sorted(self._revfiles.get(rev, [])):
131 states = self._matches[rev][fn]
132 copy = self._copies.get(rev, {}).get(fn)
133 if fn in self._skip:
134 if copy:
135 self._skip.add(copy)
136 continue
137 pstates = self._matches.get(parent, {}).get(copy or fn, [])
138 if pstates or states:
139 yield fn, ctx, pstates, states
140 del self._revfiles[rev]
141 # We will keep the matches dict for the duration of the window
142 # clear the matches dict once the window is over
143 if not self._revfiles:
144 self._matches.clear()
117 145
118 def _grepbody(self, fn, rev, body): 146 def _grepbody(self, fn, rev, body):
119 self._matches[rev].setdefault(fn, []) 147 self._matches[rev].setdefault(fn, [])
120 m = self._matches[rev][fn] 148 m = self._matches[rev][fn]
121 if body is None: 149 if body is None: