Patchwork [1,of,6] grep: explicitly pass regexp to closure functions

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 7, 2020, 12:56 p.m.
Message ID <44729154f2ab3152224b.1602075360@mimosa>
Download mbox | patch
Permalink /patch/47399/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 7, 2020, 12:56 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599632246 -32400
#      Wed Sep 09 15:17:26 2020 +0900
# Node ID 44729154f2ab3152224b89bfc565a70f832ebc3a
# Parent  d1759b2e18889eb2f58e9d348f45d76af047ba08
grep: explicitly pass regexp to closure functions

These functions will be extracted to new module.
Pulkit Goyal - Oct. 13, 2020, 7:37 a.m.
On Wed, Oct 7, 2020 at 6:29 PM Yuya Nishihara <yuya@tcha.org> wrote:
>
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1599632246 -32400
> #      Wed Sep 09 15:17:26 2020 +0900
> # Node ID 44729154f2ab3152224b89bfc565a70f832ebc3a
> # Parent  d1759b2e18889eb2f58e9d348f45d76af047ba08
> grep: explicitly pass regexp to closure functions
>
> These functions will be extracted to new module.

Queued the series, many thanks!

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3400,7 +3400,7 @@  def grep(ui, repo, pattern, *pats, **opt
 
     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 grep(ui, repo, pattern, *pats, **opt
         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 @@  def grep(ui, repo, pattern, *pats, **opt
         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 grep(ui, repo, pattern, *pats, **opt
 
     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])