grep: explicitly pass regexp to closure functions
authorYuya Nishihara <yuya@tcha.org>
Wed, 09 Sep 2020 15:17:26 +0900
changeset 45695 760bb4d74aad
parent 45694 d1c10d33a85c
child 45696 de6f2afc0247
grep: explicitly pass regexp to closure functions These functions will be extracted to new module.
mercurial/commands.py
--- a/mercurial/commands.py	Thu Oct 08 17:29:51 2020 +0530
+++ b/mercurial/commands.py	Wed Sep 09 15:17:26 2020 +0900
@@ -3400,7 +3400,7 @@
 
     getfile = util.lrucachefunc(repo.file)
 
-    def matchlines(body):
+    def matchlines(body, regexp):
         begin = 0
         linenum = 0
         while begin < len(body):
@@ -3427,7 +3427,7 @@
         def __eq__(self, other):
             return self.line == other.line
 
-        def findpos(self):
+        def findpos(self, regexp):
             """Iterate all (start, end) indices of matches"""
             yield self.colstart, self.colend
             p = self.colend
@@ -3450,7 +3450,7 @@
         if body is None:
             return
 
-        for lnum, cstart, cend, line in matchlines(body):
+        for lnum, cstart, cend, line in matchlines(body, regexp):
             s = linestate(line, lnum, cstart, cend)
             m.append(s)
 
@@ -3562,7 +3562,7 @@
 
     def displaymatches(fm, l):
         p = 0
-        for s, e in l.findpos():
+        for s, e in l.findpos(regexp):
             if p < s:
                 fm.startitem()
                 fm.write(b'text', b'%s', l.line[p:s])