Mercurial > hg-stable
diff mercurial/context.py @ 30824:6e1d54be7588
context: extract _changesinrange() out of blockancestors()
We'll need it to write a blockdescendants function in next changeset.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Mon, 16 Jan 2017 09:22:32 +0100 |
parents | 2df983125d37 |
children | 21f1f97ab212 |
line wrap: on
line diff
--- 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