[PATCH 1 of 2 evolve-ext-V4] evolve: make prune respect allowunsable

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jun 18 12:30:05 CDT 2015



On 06/17/2015 01:39 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon at fb.com>
> # Date 1432759785 25200
> #      Wed May 27 13:49:45 2015 -0700
> # Node ID adb791429c95d8ca9df9fa427b97afae14ebfc6e
> # Parent  c02cdb97ebfa29c0df40417db9e36f31f2977b4b
> evolve: make prune respect allowunsable
>
> Before this patch, the prune command was performing the same way regardless
> of the value of experimental.evolution.
> With this patch if the configuration does not allow unstability, prune won't
> create instability.
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -1928,6 +1928,10 @@ def cmdprune(ui, repo, *revs, **opts):
>           if not precs:
>               raise util.Abort('nothing to prune')
>
> +        if not obsolete.isenabled(repo, obsolete.allowunstableopt):
> +            if len(repo.revs("(%ld::) - %ld", revs, revs)) != 0:
> +                raise util.Abort(_("cannot prune in the middle of a stack"))

Do not use `if len(x) !=0` just use `if x:`. In addition to be more 
concises, this is also more efficient, smartset (stuff returned by 
revsets) can have a faster __nonzero__ method than __len__ since you do 
not have to compute the whole result to know it is not empty (while you 
need the whole result for the len).

I've fixed it and pushed to the evolve repo.

> diff --git a/tests/test-evolve.t b/tests/test-evolve.t
> --- a/tests/test-evolve.t
> +++ b/tests/test-evolve.t
> @@ -1302,3 +1302,17 @@ With only createmarkers we can only unco
>     |/
>     o  25:4c0bc042ef3b at default(draft) add j1
>     |
> +
> +Check that prune respects the allowunstable option
> +  $ hg prune 2b5cbe59aeca
> +  abort: cannot prune in the middle of a stack
> +  [255]
> +  $ hg up 07aaa06da467
> +  3 files updated, 0 files merged, 3 files removed, 0 files unresolved
> +  $ mkcommit c5_
> +  created new head
> +  $ hg prune '897e7966b9ef + 07aaa06da467'
> +  abort: cannot prune in the middle of a stack
> +  [255]
> +  $ hg prune 897e7966b9ef
> +  1 changesets pruned

We probably need a test for the more subtle case too.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list