Submitter | Denis Laxalde |
---|---|
Date | April 11, 2017, 1:09 p.m. |
Message ID | <ce5fd23baea30c83d668.1491916148@sh77.tls.logilab.fr> |
Download | mbox | patch |
Permalink | /patch/20104/ |
State | Accepted |
Headers | show |
Comments
On Tue, 11 Apr 2017 15:09:08 +0200, Denis Laxalde wrote: > # HG changeset patch > # User Denis Laxalde <denis.laxalde@logilab.fr> > # Date 1491829896 -7200 > # Mon Apr 10 15:11:36 2017 +0200 > # Node ID ce5fd23baea30c83d668a8680d2b6ed0ef7baa14 > # Parent 9259cf823690e4fcd34a4d2ecd57ced2060d2b3d > # Available At http://hg.logilab.org/users/dlaxalde/hg > # hg pull http://hg.logilab.org/users/dlaxalde/hg -r ce5fd23baea3 > 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. > > diff --git a/mercurial/context.py b/mercurial/context.py > --- a/mercurial/context.py > +++ b/mercurial/context.py > @@ -1208,6 +1208,26 @@ def blockancestors(fctx, fromline, tolin > if inrange: > yield c, linerange2 > > +def blockdescendants(fctx, fromline, toline): > + """Yield descendants of `fctx` with respect to the block of lines within > + `fromline`-`toline` range. > + """ > + diffopts = patch.diffopts(fctx._repo.ui) > + fl = fctx.filelog() > + seen = {fctx.filerev(): (fctx, (fromline, toline))} > + for i in fl.descendants([fctx.filerev()]): > + c = fctx.filectx(i) > + for x in fl.parentrevs(i): > + try: > + p, linerange2 = seen.pop(x) Maybe this only follows the first branch? The revision 'x' can have many children. > + except KeyError: > + # nullrev or other branch > + continue > + inrange, linerange1 = _changesrange(c, p, linerange2, diffopts) > + if inrange: > + yield c, linerange1 > + seen[i] = c, linerange1
Patch
diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -1208,6 +1208,26 @@ def blockancestors(fctx, fromline, tolin if inrange: yield c, linerange2 +def blockdescendants(fctx, fromline, toline): + """Yield descendants of `fctx` with respect to the block of lines within + `fromline`-`toline` range. + """ + diffopts = patch.diffopts(fctx._repo.ui) + fl = fctx.filelog() + seen = {fctx.filerev(): (fctx, (fromline, toline))} + for i in fl.descendants([fctx.filerev()]): + c = fctx.filectx(i) + for x in fl.parentrevs(i): + try: + p, linerange2 = seen.pop(x) + except KeyError: + # nullrev or other branch + continue + inrange, linerange1 = _changesrange(c, p, linerange2, diffopts) + if inrange: + yield c, linerange1 + seen[i] = c, linerange1 + class committablectx(basectx): """A committablectx object provides common functionality for a context that wants the ability to commit, e.g. workingctx or memctx."""