changeset 45719:c10c87c8fe79

grep: extract public function to register file to be skipped The main grep loop will be extracted to a searcher method, but this skipping condition depends on the result of display() function.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 09 Sep 2020 17:04:44 +0900
parents 87c35b5a14eb
children 508dfd1c18df
files mercurial/commands.py mercurial/grep.py
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Oct 13 16:44:57 2020 -0400
+++ b/mercurial/commands.py	Wed Sep 09 17:04:44 2020 +0900
@@ -3549,9 +3549,7 @@
                 r = display(fm, fn, ctx, pstates, states)
                 found = found or r
                 if r and not diff and not all_files:
-                    skip.add(fn)
-                    if copy:
-                        skip.add(copy)
+                    searcher.skipfile(fn, rev)
         del revfiles[rev]
         # We will keep the matches dict for the duration of the window
         # clear the matches dict once the window is over
--- a/mercurial/grep.py	Tue Oct 13 16:44:57 2020 -0400
+++ b/mercurial/grep.py	Wed Sep 09 17:04:44 2020 +0900
@@ -107,6 +107,14 @@
         self._skip = set()
         self._revfiles = {}
 
+    def skipfile(self, fn, rev):
+        """Exclude the given file (and the copy at the specified revision)
+        from future search"""
+        copy = self._copies.get(rev, {}).get(fn)
+        self._skip.add(fn)
+        if copy:
+            self._skip.add(copy)
+
     def _grepbody(self, fn, rev, body):
         self._matches[rev].setdefault(fn, [])
         m = self._matches[rev][fn]