[PATCH 4 of 5 V2] revset: add _optimizeand function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Oct 1 20:25:36 UTC 2014



On 09/30/2014 01:02 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1412036832 25200
> #      Mon Sep 29 17:27:12 2014 -0700
> # Node ID afa88d660f03f3e19a4f9c1cba2442446a4db733
> # Parent  7d4c0bc4debf9efcc673c24e880d3d831bd06ef9
> revset: add _optimizeand function
>
> Adds an _optimizeand function that takes two sets (the iterate set, and the
> check set) and reverses them if the iterate set is bigger than the check set.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2206,6 +2206,22 @@ def _getlengthhint(revs):
>       else:
>           return None
>
> +def _optimizeand(iterate, check):
> +    """Return the given sets in the optimal order for iterating and checking
> +    containment. The iterate set is the first return arg, the check set is the
> +    second.
> +    """
> +    iteratelen = _getlengthhint(iterate)
> +    checklen = _getlengthhint(check)
> +    if iteratelen is not None and checklen is not None:
> +        # Don't reorder if the `check` is a set. Many revsets assume the result
> +        # will be a smart class, and if we reorder such that there is a set on
> +        # the left of a X & Y expression, the result is a set, which breaks
> +        # things.
> +        if iteratelen > checklen and not isinstance(check, set):

isinstance set if not going to be enought. There is plenty of similar 
smartset class that are actually not smartclass (hopefully their will be 
all smartclass when I'll be done refactoring for the order stuff). you 
have to check for smartclass specific attribute like "isascending".

-- 
Pierre-Yves David



More information about the Mercurial-devel mailing list