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

login
register
mail settings
Submitter Laurent Charignon
Date June 17, 2015, 8:39 p.m.
Message ID <adb791429c95d8ca9df9.1434573580@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/9697/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Laurent Charignon - June 17, 2015, 8:39 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@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.
Pierre-Yves David - June 18, 2015, 5:30 p.m.
On 06/17/2015 01:39 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@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@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 - June 18, 2015, 5:35 p.m.
On 06/18/2015 10:30 AM, Pierre-Yves David wrote:
>
>
> On 06/17/2015 01:39 PM, Laurent Charignon wrote:
>> # HG changeset patch
>> # User Laurent Charignon <lcharignon@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.

Actually I've not, because the tests fails...

Patch

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"))
+
         # defines successors changesets
         sucs = scmutil.revrange(repo, succs)
         sucs.sort()
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@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