comparison 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
comparison
equal deleted inserted replaced
30823:806a830e6612 30824:6e1d54be7588
1154 # hard for renames 1154 # hard for renames
1155 c = self._filelog.children(self._filenode) 1155 c = self._filelog.children(self._filenode)
1156 return [filectx(self._repo, self._path, fileid=x, 1156 return [filectx(self._repo, self._path, fileid=x,
1157 filelog=self._filelog) for x in c] 1157 filelog=self._filelog) for x in c]
1158 1158
1159 def _changesrange(fctx1, fctx2, linerange2, diffopts):
1160 """Return `(diffinrange, linerange1)` where `diffinrange` is True
1161 if diff from fctx2 to fctx1 has changes in linerange2 and
1162 `linerange1` is the new line range for fctx1.
1163 """
1164 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
1165 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
1166 diffinrange = any(stype == '!' for _, stype in filteredblocks)
1167 return diffinrange, linerange1
1168
1159 def blockancestors(fctx, fromline, toline): 1169 def blockancestors(fctx, fromline, toline):
1160 """Yield ancestors of `fctx` with respect to the block of lines within 1170 """Yield ancestors of `fctx` with respect to the block of lines within
1161 `fromline`-`toline` range. 1171 `fromline`-`toline` range.
1162 """ 1172 """
1163 def changesrange(fctx1, fctx2, linerange2): 1173 diffopts = patch.diffopts(fctx._repo.ui)
1164 """Return `(diffinrange, linerange1)` where `diffinrange` is True
1165 if diff from fctx2 to fctx1 has changes in linerange2 and
1166 `linerange1` is the new line range for fctx1.
1167 """
1168 diffopts = patch.diffopts(fctx._repo.ui)
1169 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
1170 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
1171 diffinrange = any(stype == '!' for _, stype in filteredblocks)
1172 return diffinrange, linerange1
1173
1174 visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))} 1174 visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
1175 while visit: 1175 while visit:
1176 c, linerange2 = visit.pop(max(visit)) 1176 c, linerange2 = visit.pop(max(visit))
1177 pl = c.parents() 1177 pl = c.parents()
1178 if not pl: 1178 if not pl:
1179 # The block originates from the initial revision. 1179 # The block originates from the initial revision.
1180 yield c 1180 yield c
1181 continue 1181 continue
1182 inrange = False 1182 inrange = False
1183 for p in pl: 1183 for p in pl:
1184 inrangep, linerange1 = changesrange(p, c, linerange2) 1184 inrangep, linerange1 = _changesrange(p, c, linerange2, diffopts)
1185 inrange = inrange or inrangep 1185 inrange = inrange or inrangep
1186 if linerange1[0] == linerange1[1]: 1186 if linerange1[0] == linerange1[1]:
1187 # Parent's linerange is empty, meaning that the block got 1187 # Parent's linerange is empty, meaning that the block got
1188 # introduced in this revision; no need to go futher in this 1188 # introduced in this revision; no need to go futher in this
1189 # branch. 1189 # branch.