D6140: revset: add new contiguous(x) function for "x::x"

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Mar 15 06:48:24 EDT 2019


I am a fan of this function, I need this on a regular basis. Having an 
explicit function for this also open the way to various optimization. 
For example we know that a set already has this property we could skip 
all computation.

I am ambivalent about the naming however. It feels a bit odd. There are 
case where it could be misleading.

Lets look at the following case:

   c e
   | |
   b d
   |/
   a

the revset `(b+c+d+e)::(b+c+d+e)` returns the same `b+c+d+e`, however 
the set is not "contiguous" as `b+c` and `d+e` as not connected.

This feels a bit more like a "closure" operation to me.

Cheers,

On 3/15/19 6:27 AM, martinvonz (Martin von Zweigbergk) wrote:
> martinvonz created this revision.
> Herald added a subscriber: mercurial-devel.
> Herald added a reviewer: hg-reviewers.
> 
> REVISION SUMMARY
>    "x::x" is a useful trick for making a range contiguous, but it gets
>    annoying if "x" is a long expression. Let's provide a simple function
>    that helps with that. It also makes it the trick more discoverable.
> 
> REPOSITORY
>    rHG Mercurial
> 
> REVISION DETAIL
>    https://phab.mercurial-scm.org/D6140
> 
> AFFECTED FILES
>    mercurial/revset.py
>    tests/test-revset.t
> 
> CHANGE DETAILS
> 
> diff --git a/tests/test-revset.t b/tests/test-revset.t
> --- a/tests/test-revset.t
> +++ b/tests/test-revset.t
> @@ -1314,6 +1314,47 @@
>     2
>     3
>   
> +test contiguous
> +
> +  $ hg log -G -T '{rev}\n' --config experimental.graphshorten=True
> +  @  9
> +  o  8
> +  | o  7
> +  | o  6
> +  |/|
> +  | o  5
> +  o |  4
> +  | o  3
> +  o |  2
> +  |/
> +  o  1
> +  o  0
> +
> +  $ log 'contiguous(0+2)'
> +  0
> +  1
> +  2
> +  $ log 'contiguous(2+0)'
> +  0
> +  1
> +  2
> +  $ log 'contiguous(2+3)'
> +  2
> +  3
> +  $ log 'contiguous(3+2)'
> +  2
> +  3
> +  $ log 'contiguous(3+7)'
> +  3
> +  5
> +  6
> +  7
> +  $ log 'contiguous(9+3+4)'
> +  3
> +  4
> +  8
> +  9
> +
>   test author
>   
>     $ log 'author(bob)'
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -714,6 +714,16 @@
>   
>       return subset.filter(matches, condrepr=('<contains %r>', pat))
>   
> + at predicate('contiguous(set)', safe=True, takeorder=True)
> +def contiguous(repo, subset, x, order):
> +    """Changesets that have both ancestors and descendants in the set. This
> +    effectively fills in gaps in the set to make it contiguous, without adding
> +    new common ancestors or common descendants.
> +
> +     "contiguous(x)" is identical to "x::x".
> +    """
> +    return dagrange(repo, subset, x, x, order)
> +
>   @predicate('converted([id])', safe=True)
>   def converted(repo, subset, x):
>       """Changesets converted from the given identifier in the old repository if
> 
> 
> 
> To: martinvonz, #hg-reviewers
> Cc: mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
> 

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list