[PATCH 1 of 3] context: extract _changesinrange() out of blockancestors()

Denis Laxalde denis.laxalde at logilab.fr
Mon Jan 16 11:03:29 UTC 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1484554952 -3600
#      Mon Jan 16 09:22:32 2017 +0100
# Node ID 42d96c182debdeeb8103218aab78ab5a73001758
# Parent  98bfce9bd5e53e88d1c94af5f24b0e91795e18a3
# EXP-Topic linerange-log/revset-descendants
context: extract _changesinrange() out of blockancestors()

We'll need it to write a blockdescendants function in next changeset.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1156,21 +1156,21 @@ class filectx(basefilectx):
         return [filectx(self._repo, self._path, fileid=x,
                         filelog=self._filelog) for x in c]
 
+def _changesrange(fctx1, fctx2, linerange2, diffopts):
+    """Return `(diffinrange, linerange1)` where `diffinrange` is True
+    if diff from fctx2 to fctx1 has changes in linerange2 and
+    `linerange1` is the new line range for fctx1.
+    """
+    blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
+    filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
+    diffinrange = any(stype == '!' for _, stype in filteredblocks)
+    return diffinrange, linerange1
+
 def blockancestors(fctx, fromline, toline):
     """Yield ancestors of `fctx` with respect to the block of lines within
     `fromline`-`toline` range.
     """
-    def changesrange(fctx1, fctx2, linerange2):
-        """Return `(diffinrange, linerange1)` where `diffinrange` is True
-        if diff from fctx2 to fctx1 has changes in linerange2 and
-        `linerange1` is the new line range for fctx1.
-        """
-        diffopts = patch.diffopts(fctx._repo.ui)
-        blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
-        filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
-        diffinrange = any(stype == '!' for _, stype in filteredblocks)
-        return diffinrange, linerange1
-
+    diffopts = patch.diffopts(fctx._repo.ui)
     visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
     while visit:
         c, linerange2 = visit.pop(max(visit))
@@ -1181,7 +1181,7 @@ def blockancestors(fctx, fromline, tolin
             continue
         inrange = False
         for p in pl:
-            inrangep, linerange1 = changesrange(p, c, linerange2)
+            inrangep, linerange1 = _changesrange(p, c, linerange2, diffopts)
             inrange = inrange or inrangep
             if linerange1[0] == linerange1[1]:
                 # Parent's linerange is empty, meaning that the block got


More information about the Mercurial-devel mailing list