Patchwork [1,of,7] grep: extract public function to register file to be skipped

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 14, 2020, 2:13 p.m.
Message ID <d36d703c291e45670245.1602684811@mimosa>
Download mbox | patch
Permalink /patch/47456/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 14, 2020, 2:13 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599638684 -32400
#      Wed Sep 09 17:04:44 2020 +0900
# Node ID d36d703c291e45670245384440993ff70ad17da4
# Parent  0428978bca22dc1173577ca6247d588182805b78
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.
Pulkit Goyal - Oct. 15, 2020, 12:11 p.m.
On Wed, Oct 14, 2020 at 7:47 PM Yuya Nishihara <yuya@tcha.org> wrote:
>
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1599638684 -32400
> #      Wed Sep 09 17:04:44 2020 +0900
> # Node ID d36d703c291e45670245384440993ff70ad17da4
> # Parent  0428978bca22dc1173577ca6247d588182805b78
> 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.

Queued the series, many thanks!

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3549,9 +3549,7 @@  def grep(ui, repo, pattern, *pats, **opt
                 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
diff --git a/mercurial/grep.py b/mercurial/grep.py
--- a/mercurial/grep.py
+++ b/mercurial/grep.py
@@ -107,6 +107,14 @@  class grepsearcher(object):
         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]