Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 31937:826e600605f6
context: add a blockdescendants function
This is symmetrical with blockancestors() and yields descendants of a filectx
with changes in the given line range. The noticeable difference is that the
algorithm does not follow renames (probably because filelog.descendants() does
not), so we are missing branches with renames.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Mon, 10 Apr 2017 15:11:36 +0200 |
parents | 7973e0a15bd4 |
children | 4c2c30bc38b4 |
comparison
equal
deleted
inserted
replaced
31936:806f9a883b4f | 31937:826e600605f6 |
---|---|
1206 continue | 1206 continue |
1207 visit[p.linkrev(), p.filenode()] = p, linerange1 | 1207 visit[p.linkrev(), p.filenode()] = p, linerange1 |
1208 if inrange: | 1208 if inrange: |
1209 yield c, linerange2 | 1209 yield c, linerange2 |
1210 | 1210 |
1211 def blockdescendants(fctx, fromline, toline): | |
1212 """Yield descendants of `fctx` with respect to the block of lines within | |
1213 `fromline`-`toline` range. | |
1214 """ | |
1215 diffopts = patch.diffopts(fctx._repo.ui) | |
1216 fl = fctx.filelog() | |
1217 seen = {fctx.filerev(): (fctx, (fromline, toline))} | |
1218 for i in fl.descendants([fctx.filerev()]): | |
1219 c = fctx.filectx(i) | |
1220 for x in fl.parentrevs(i): | |
1221 try: | |
1222 p, linerange2 = seen.pop(x) | |
1223 except KeyError: | |
1224 # nullrev or other branch | |
1225 continue | |
1226 inrange, linerange1 = _changesrange(c, p, linerange2, diffopts) | |
1227 if inrange: | |
1228 yield c, linerange1 | |
1229 seen[i] = c, linerange1 | |
1230 | |
1211 class committablectx(basectx): | 1231 class committablectx(basectx): |
1212 """A committablectx object provides common functionality for a context that | 1232 """A committablectx object provides common functionality for a context that |
1213 wants the ability to commit, e.g. workingctx or memctx.""" | 1233 wants the ability to commit, e.g. workingctx or memctx.""" |
1214 def __init__(self, repo, text="", user=None, date=None, extra=None, | 1234 def __init__(self, repo, text="", user=None, date=None, extra=None, |
1215 changes=None): | 1235 changes=None): |