# HG changeset patch # User Denis Laxalde # Date 1484554952 -3600 # Node ID 6e1d54be7588e215ca931cf584c40ffb61daecba # Parent 806a830e66123c92a3f457e3c244456adeb2af10 context: extract _changesinrange() out of blockancestors() We'll need it to write a blockdescendants function in next changeset. diff -r 806a830e6612 -r 6e1d54be7588 mercurial/context.py --- a/mercurial/context.py Sat Jan 14 01:23:07 2017 +0530 +++ b/mercurial/context.py Mon Jan 16 09:22:32 2017 +0100 @@ -1156,21 +1156,21 @@ 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 @@ 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