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

login
register
mail settings
Submitter Denis Laxalde
Date Jan. 16, 2017, 11:03 a.m.
Message ID <42d96c182debdeeb8103.1484564609@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/18228/
State Accepted
Headers show

Comments

Denis Laxalde - Jan. 16, 2017, 11:03 a.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@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.
Yuya Nishihara - Jan. 16, 2017, 1:51 p.m.
On Mon, 16 Jan 2017 12:03:29 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@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()

The first patch itself looks nice. Queued this, thanks.

Patch

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