##// END OF EJS Templates
grep: extract main search loop as searcher method...
Yuya Nishihara -
r46313:f9d3ff23 default
parent child Browse files
Show More
@@ -3403,8 +3403,6 b' def grep(ui, repo, pattern, *pats, **opt'
3403 3403 )
3404 3404
3405 3405 getfile = searcher._getfile
3406 matches = searcher._matches
3407 copies = searcher._copies
3408 3406
3409 3407 uipathfn = scmutil.getuipathfn(repo)
3410 3408
@@ -3514,8 +3512,6 b' def grep(ui, repo, pattern, *pats, **opt'
3514 3512 fm.data(matched=False)
3515 3513 fm.end()
3516 3514
3517 skip = searcher._skip
3518 revfiles = searcher._revfiles
3519 3515 found = False
3520 3516
3521 3517 wopts = logcmdutil.walkopts(
@@ -3532,29 +3528,11 b' def grep(ui, repo, pattern, *pats, **opt'
3532 3528
3533 3529 ui.pager(b'grep')
3534 3530 fm = ui.formatter(b'grep', opts)
3535 for ctx in scmutil.walkchangerevs(
3536 repo, revs, makefilematcher, searcher._prep
3537 ):
3538 rev = ctx.rev()
3539 parent = ctx.p1().rev()
3540 for fn in sorted(revfiles.get(rev, [])):
3541 states = matches[rev][fn]
3542 copy = copies.get(rev, {}).get(fn)
3543 if fn in skip:
3544 if copy:
3545 skip.add(copy)
3546 continue
3547 pstates = matches.get(parent, {}).get(copy or fn, [])
3548 if pstates or states:
3549 r = display(fm, fn, ctx, pstates, states)
3550 found = found or r
3551 if r and not diff and not all_files:
3552 searcher.skipfile(fn, rev)
3553 del revfiles[rev]
3554 # We will keep the matches dict for the duration of the window
3555 # clear the matches dict once the window is over
3556 if not revfiles:
3557 matches.clear()
3531 for fn, ctx, pstates, states in searcher.searchfiles(revs, makefilematcher):
3532 r = display(fm, fn, ctx, pstates, states)
3533 found = found or r
3534 if r and not diff and not all_files:
3535 searcher.skipfile(fn, ctx.rev())
3558 3536 fm.end()
3559 3537
3560 3538 return not found
@@ -115,6 +115,34 b' class grepsearcher(object):'
115 115 if copy:
116 116 self._skip.add(copy)
117 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()
145
118 146 def _grepbody(self, fn, rev, body):
119 147 self._matches[rev].setdefault(fn, [])
120 148 m = self._matches[rev][fn]
General Comments 0
You need to be logged in to leave comments. Login now