[PATCH 7 of 9] grep: yield the start and end position of matches in the body

Idan Kamara idankk86 at gmail.com
Sun Oct 14 15:54:24 CDT 2012


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1349699807 -7200
# Node ID 726226e2c3947c4b1bc1e5b0cd8a75e28d5f2d27
# Parent  1c796e1364f2563ce655901a400a995f6f1d2230
grep: yield the start and end position of matches in the body

Will be used for post-processing the list of matches.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2964,12 +2964,15 @@
                     if lstart <= s <= lend and e > lend:
                         begin = body.find('\n', e) + 1 or len(body) + 1
                         lend = begin - 1
-            yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
+            yield (linenum, lstart, lend, mstart - lstart, mend - lstart,
+                   body[lstart:lend])
 
     class linestate(object):
-        def __init__(self, line, linenum, colstart, colend):
+        def __init__(self, line, linenum, lstart, lend, colstart, colend):
             self.line = line
             self.linenum = linenum
+            self.lstart = lstart
+            self.lend = lend
             self.colstart = colstart
             self.colend = colend
 
@@ -2984,8 +2987,8 @@
     def grepbody(fn, rev, body):
         matches[rev].setdefault(fn, [])
         m = matches[rev][fn]
-        for lnum, cstart, cend, line in matchlines(body):
-            s = linestate(line, lnum, cstart, cend)
+        for lnum, lstart, lend, cstart, cend, line in matchlines(body):
+            s = linestate(line, lnum, lstart, lend, cstart, cend)
             m.append(s)
 
     def difflinestates(a, b):


More information about the Mercurial-devel mailing list