From patchwork Sun Mar 20 05:02:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 3, evolve-ext, V2] evolve: factor out check for creating unstable commits From: Siddharth Agarwal X-Patchwork-Id: 13979 Message-Id: <62cee591d6b306cfa8d1.1458450146@dev666.prn1.facebook.com> To: Date: Sat, 19 Mar 2016 22:02:26 -0700 # HG changeset patch # User Siddharth Agarwal # Date 1458449988 25200 # Sat Mar 19 21:59:48 2016 -0700 # Branch stable # Node ID 62cee591d6b306cfa8d1f30acbcc4cae972d79ff # Parent 6a025b84e174d08fdb485d1f049be17077c671c8 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 @@ -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)