[PATCH 2 of 3] context: add a blockdescendants function

Yuya Nishihara yuya at tcha.org
Mon Jan 16 08:52:42 EST 2017


On Mon, 16 Jan 2017 12:03:30 +0100, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1484554990 -3600
> #      Mon Jan 16 09:23:10 2017 +0100
> # Node ID 69653aeb724d00f3db816670896c2b974c9aa39b
> # Parent  42d96c182debdeeb8103218aab78ab5a73001758
> # EXP-Topic linerange-log/revset-descendants
> context: add a blockdescendants function

(I haven't read this series carefully, so I might be wrong.)

> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -1192,6 +1192,20 @@ def blockancestors(fctx, fromline, tolin
>          if inrange:
>              yield c
>  
> +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)
> +    visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
> +    while visit:
> +        p, linerange2 = visit.pop(max(visit))

Shouldn't it be min(visit) ?

> +        for c in p.children():
> +            inrange, linerange1 = _changesrange(c, p, linerange2, diffopts)
> +            visit[c.linkrev(), c.filenode()] = c, linerange1
> +            if inrange:
> +                yield c

Perhaps it's quite inefficient to call children() repeatedly since
revlog.children() scans cur:tip nodes. revset._revdescendants() might
provide a hint for a better implementation.


More information about the Mercurial-devel mailing list