##// END OF EJS Templates
context: add a `blockancestors(fctx, fromline, toline)` function...
Denis Laxalde -
r30718:ce662ee4 default
parent child Browse files
Show More
@@ -1153,6 +1153,42 b' class filectx(basefilectx):'
1153 return [filectx(self._repo, self._path, fileid=x,
1153 return [filectx(self._repo, self._path, fileid=x,
1154 filelog=self._filelog) for x in c]
1154 filelog=self._filelog) for x in c]
1155
1155
1156 def blockancestors(fctx, fromline, toline):
1157 """Yield ancestors of `fctx` with respect to the block of lines within
1158 `fromline`-`toline` range.
1159 """
1160 def changesrange(fctx1, fctx2, linerange2):
1161 """Return `(diffinrange, linerange1)` where `diffinrange` is True
1162 if diff from fctx2 to fctx1 has changes in linerange2 and
1163 `linerange1` is the new line range for fctx1.
1164 """
1165 diffopts = patch.diffopts(fctx._repo.ui)
1166 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
1167 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
1168 diffinrange = any(stype == '!' for _, stype in filteredblocks)
1169 return diffinrange, linerange1
1170
1171 visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
1172 while visit:
1173 c, linerange2 = visit.pop(max(visit))
1174 pl = c.parents()
1175 if not pl:
1176 # The block originates from the initial revision.
1177 yield c
1178 continue
1179 inrange = False
1180 for p in pl:
1181 inrangep, linerange1 = changesrange(p, c, linerange2)
1182 inrange = inrange or inrangep
1183 if linerange1[0] == linerange1[1]:
1184 # Parent's linerange is empty, meaning that the block got
1185 # introduced in this revision; no need to go futher in this
1186 # branch.
1187 continue
1188 visit[p.linkrev(), p.filenode()] = p, linerange1
1189 if inrange:
1190 yield c
1191
1156 class committablectx(basectx):
1192 class committablectx(basectx):
1157 """A committablectx object provides common functionality for a context that
1193 """A committablectx object provides common functionality for a context that
1158 wants the ability to commit, e.g. workingctx or memctx."""
1194 wants the ability to commit, e.g. workingctx or memctx."""
General Comments 0
You need to be logged in to leave comments. Login now