Patchwork [2,of,4,V3,evolve-ext] evolve: factor out check for creating unstable commits

login
register
mail settings
Submitter Siddharth Agarwal
Date April 18, 2016, 6:14 p.m.
Message ID <68dadb249e521f679603.1461003276@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/14725/
State Superseded
Delegated to: Pierre-Yves David
Headers show

Comments

Siddharth Agarwal - April 18, 2016, 6:14 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1461003082 25200
#      Mon Apr 18 11:11:22 2016 -0700
# Node ID 68dadb249e521f6796030e99f682340c388ce695
# Parent  ee4f78842ce1acfbae7f8557f99e3454a137cde2
evolve: factor out check for creating unstable commits

This check is pretty non-trivial, and we do it in two places already. We're
going to do it in a third place soon.
Simon Farnsworth - April 25, 2016, 9:58 p.m.
On 18/04/2016 19:14, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1461003082 25200
> #      Mon Apr 18 11:11:22 2016 -0700
> # Node ID 68dadb249e521f6796030e99f682340c388ce695
> # Parent  ee4f78842ce1acfbae7f8557f99e3454a137cde2
> evolve: factor out check for creating unstable commits
>
> This check is pretty non-trivial, and we do it in two places already. We're
> going to do it in a third place soon.
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -2501,9 +2501,8 @@ def cmdprune(ui, repo, *revs, **opts):
>           if not precs:
>               raise error.Abort('nothing to prune')
>
> -        if not obsolete.isenabled(repo, obsolete.allowunstableopt):
> -            if repo.revs("(%ld::) - %ld", revs, revs):
> -                raise error.Abort(_("cannot prune in the middle of a stack"))
> +        if _newdisallowedunstable(repo, revs):
> +            raise error.Abort(_("cannot prune in the middle of a stack"))
>
>           # defines successors changesets
>           sucs = scmutil.revrange(repo, succs)
> @@ -3163,13 +3162,17 @@ def _foldcheck(repo, revs):
>           raise error.Abort(_("cannot fold non-linear revisions "
>                              "(multiple heads given)"))
>       head = repo[heads.first()]
> -    disallowunstable = not obsolete.isenabled(repo, obsolete.allowunstableopt)
> -    if disallowunstable:
> -        if repo.revs("(%ld::) - %ld", revs, revs):
> -            raise error.Abort(_("cannot fold chain not ending with a head "\
> -                               "or with branching"))
> +    if _newdisallowedunstable(repo, revs):
> +        raise error.Abort(_("cannot fold chain not ending with a head "\
> +                            "or with branching"))
>       return root, head
>
> +def _newdisallowedunstable(repo, revs):
> +    allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
> +    if allowunstable:
> +        return revset.baseset()
> +    return repo.revs("(%ld::) - %ld", revs, revs)
> +

I don't like this name - where's _olddisallowedunstable?; would 
"_disallownewunstable" or "_disallowunstable" be better?

>   @eh.wrapcommand('graft')
>   def graftwrapper(orig, ui, repo, *revs, **kwargs):
>       kwargs = dict(kwargs)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=mEgSWILcY4c4W3zjApBQLA&m=QSuWfvcQT6g58ytjUKrJC0OYYAYWrGMQ7z6rp0kuBRU&s=VqnMcwSa6hmxDJl3pkP5ntoHVy7WRDgFi2p0xVcJ0xI&e=
>
Siddharth Agarwal - April 25, 2016, 10:32 p.m.
On 4/25/16 14:58, Simon Farnsworth wrote:
> I don't like this name - where's _olddisallowedunstable?; would 
> "_disallownewunstable" or "_disallowunstable" be better? 


_disallownewunstable sounds good to me, thanks.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2501,9 +2501,8 @@  def cmdprune(ui, repo, *revs, **opts):
         if not precs:
             raise error.Abort('nothing to prune')
 
-        if not obsolete.isenabled(repo, obsolete.allowunstableopt):
-            if repo.revs("(%ld::) - %ld", revs, revs):
-                raise error.Abort(_("cannot prune in the middle of a stack"))
+        if _newdisallowedunstable(repo, revs):
+            raise error.Abort(_("cannot prune in the middle of a stack"))
 
         # defines successors changesets
         sucs = scmutil.revrange(repo, succs)
@@ -3163,13 +3162,17 @@  def _foldcheck(repo, revs):
         raise error.Abort(_("cannot fold non-linear revisions "
                            "(multiple heads given)"))
     head = repo[heads.first()]
-    disallowunstable = not obsolete.isenabled(repo, obsolete.allowunstableopt)
-    if disallowunstable:
-        if repo.revs("(%ld::) - %ld", revs, revs):
-            raise error.Abort(_("cannot fold chain not ending with a head "\
-                               "or with branching"))
+    if _newdisallowedunstable(repo, revs):
+        raise error.Abort(_("cannot fold chain not ending with a head "\
+                            "or with branching"))
     return root, head
 
+def _newdisallowedunstable(repo, revs):
+    allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
+    if allowunstable:
+        return revset.baseset()
+    return repo.revs("(%ld::) - %ld", revs, revs)
+
 @eh.wrapcommand('graft')
 def graftwrapper(orig, ui, repo, *revs, **kwargs):
     kwargs = dict(kwargs)