[PATCH 2 of 5] revset: insert _reorder to fix ordering of inner OR and some functions (BC)

Sean Farley sean at farley.io
Tue May 31 21:12:24 EDT 2016


Yuya Nishihara <yuya at tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1455629461 -32400
> #      Tue Feb 16 22:31:01 2016 +0900
> # Node ID 2ec0a482eea2f8cfcd19b3d3fa39457c3bf3c6f3
> # Parent  a63e5cf3d8c09e8d2265c252d2f36bbdff18b663
> revset: insert _reorder to fix ordering of inner OR and some functions (BC)
>
> This fixes the order of 'x & (y | z)' and 'x & _list(...)' by inserting
> '_reorder' function. Still 'x & y:z', 'x & reverse(y)' and 'x & sort(y)'
> have the ordering issue, which should be fixed by subsequent patches.
>
> Originally I was going to add a property to @predicate to mark a function,
> but that seems not ideal because most functions should not have such property,
> and we will need a different optimization trick per function.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -1153,6 +1153,7 @@ def head(repo, subset, x):
>      # This does not break because of other fullreposet misbehavior.
>      # XXX We should combine with subset first: 'subset & baseset(...)'. This is
>      # necessary to ensure we preserve the order in subset.
> +    # Remove 'head' from _orderingsymbols if you've fixed the issue.
>      return baseset(hs) & subset
>  
>  @predicate('heads(set)', safe=True)
> @@ -1685,6 +1686,13 @@ def removes(repo, subset, x):
>      pat = getstring(x, _("removes requires a pattern"))
>      return checkstatus(repo, subset, pat, 2)
>  
> + at predicate('_reorder(set)', safe=True)
> +def _reorder(repo, subset, x):
> +    # Evaluate right-hand-side expression 'set' and reorder the result set
> +    # according to the left-hand-side set 'subset'
> +    rs = getset(repo, subset, x)
> +    return subset & rs
> +
>  @predicate('rev(number)', safe=True)
>  def rev(repo, subset, x):
>      """Revision with the given numeric identifier.
> @@ -2067,6 +2075,18 @@ methods = {
>      "parentpost": p1,
>  }
>  
> +# symbols which have own ordering rules and disregard the order of input set.
> +# few symbols should be listed. almost all symbols should follow the input
> +# order (i.e. they should do 'subset & x' or 'subset.filter(x)'.
> +_orderingsymbols = set([
> +    'head',
> +    'reverse',
> +    'sort',
> +    '_list',
> +    '_intlist',
> +    '_hexlist',
> +])
> +
>  # constants for ordering policy, used in _optimize():
>  # 1. starts with 'define'
>  # 2. shifts to 'follow' by 'x & y'
> @@ -2085,6 +2105,12 @@ methods = {
>      _followorder: _followorder,
>  }
>  
> +def _fixfolloworder(x, order):
> +    if order == _followorder:
> +        return ('func', ('symbol', '_reorder'), x)
> +    else:
> +        return x

Minor nit: I'd prefer this return to be outside the 'if' block. Could be
fixed in-flight, though.


More information about the Mercurial-devel mailing list