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

login
register
mail settings
Submitter Siddharth Agarwal
Date March 10, 2016, 9:24 a.m.
Message ID <acb48e8d739cec3b824a.1457601858@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/13737/
State Changes Requested
Delegated to: Laurent Charignon
Headers show

Comments

Siddharth Agarwal - March 10, 2016, 9:24 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1457595597 28800
#      Wed Mar 09 23:39:57 2016 -0800
# Branch stable
# Node ID acb48e8d739cec3b824a088843d8c432a34d2fd6
# Parent  00313a1e9fea09ccdf5ce19b362fc254e4eb40eb
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.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2349,9 +2349,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 _willcreatedisallowedunstable(repo, revs):
+            raise error.Abort(_("cannot prune in the middle of a stack"))
 
         # defines successors changesets
         sucs = scmutil.revrange(repo, succs)
@@ -3011,13 +3010,15 @@  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 _willcreatedisallowedunstable(repo, revs):
+        raise error.Abort(_("cannot fold chain not ending with a head "\
+                            "or with branching"))
     return root, head
 
+def _willcreatedisallowedunstable(repo, revs):
+    allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
+    return not allowunstable and bool(repo.revs("(%ld::) - %ld", revs, revs))
+
 @eh.wrapcommand('graft')
 def graftwrapper(orig, ui, repo, *revs, **kwargs):
     kwargs = dict(kwargs)