comparison mercurial/context.py @ 31075:21f1f97ab212

context: add a followfirst flag to blockancestors
author Denis Laxalde <denis.laxalde@logilab.fr>
date Mon, 16 Jan 2017 17:08:25 +0100
parents 6e1d54be7588
children 0e07855e6054
comparison
equal deleted inserted replaced
31074:2912b06905dc 31075:21f1f97ab212
1164 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts) 1164 blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
1165 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2) 1165 filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
1166 diffinrange = any(stype == '!' for _, stype in filteredblocks) 1166 diffinrange = any(stype == '!' for _, stype in filteredblocks)
1167 return diffinrange, linerange1 1167 return diffinrange, linerange1
1168 1168
1169 def blockancestors(fctx, fromline, toline): 1169 def blockancestors(fctx, fromline, toline, followfirst=False):
1170 """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
1171 `fromline`-`toline` range. 1171 `fromline`-`toline` range.
1172 """ 1172 """
1173 diffopts = patch.diffopts(fctx._repo.ui) 1173 diffopts = patch.diffopts(fctx._repo.ui)
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 followfirst:
1179 pl = pl[:1]
1178 if not pl: 1180 if not pl:
1179 # The block originates from the initial revision. 1181 # The block originates from the initial revision.
1180 yield c 1182 yield c
1181 continue 1183 continue
1182 inrange = False 1184 inrange = False