[PATCH 5 of 5] rank: compute property incrementally

Pierre-Yves David pierre-yves.david at octobus.net
Mon Jan 31 15:57:40 UTC 2022


On 1/31/22 15:03, pacien wrote:
> # HG changeset patch
> # User pacien <pacien.trangirard at pacien.net>
> # Date 1643367284 -3600
> #      Fri Jan 28 11:54:44 2022 +0100
> # Node ID 13b044b7e39299156aac33e68550b7004ad21cba
> # Parent  04b7286cc3c4c7e332294183cfb87366d9748ca6
> # EXP-Topic cl2-rank
> rank: compute property incrementally
>
> This replace the naive rank computation with more efficient incremental
> method, avoiding computing the whole ancestor set when possible.
>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -2491,7 +2491,17 @@
>           # maybe the index.append should compute it when applicable instead
>           rank = RANK_UNKNOWN
>           if self._format_version == CHANGELOGV2:
> -            rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
> +            if (p1r, p2r) == (nullrev, nullrev):
> +                rank = 1
> +            elif p1r != nullrev and p2r == nullrev:
> +                rank = 1 + self.fast_rank(p1r)
> +            elif p1r == nullrev and p2r != nullrev:
> +                rank = 1 + self.fast_rank(p2r)
> +            else:  # merge node
> +                # TODO: use exclusive part size from leap info when those will
> +                #       be available
> +                rank = (1 +
> +                  sum(1 for _ in self.ancestors([p1r, p2r], inclusive=True)))


You don't need to wait for leap based traversal, you can already use 
`self.findmissing` to have more efficient computation.


-- 
Pierre-Yves David




More information about the Mercurial-devel mailing list