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.
--- a/hgext/evolve.py Mon Apr 25 16:24:42 2016 -0700
+++ b/hgext/evolve.py Mon Apr 25 16:24:42 2016 -0700
@@ -2509,9 +2509,8 @@
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 _disallowednewunstable(repo, revs):
+ raise error.Abort(_("cannot prune in the middle of a stack"))
# defines successors changesets
sucs = scmutil.revrange(repo, succs)
@@ -3172,13 +3171,17 @@
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 _disallowednewunstable(repo, revs):
+ raise error.Abort(_("cannot fold chain not ending with a head "\
+ "or with branching"))
return root, head
+def _disallowednewunstable(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)