evolve: factor out sanity checks for folds
We're going to use the same checks in another context in an upcoming patch.
--- a/hgext/evolve.py Thu Apr 21 06:12:20 2016 +0000
+++ b/hgext/evolve.py Mon Apr 25 16:24:42 2016 -0700
@@ -3122,23 +3122,8 @@
ui.write_err(_('single revision specified, nothing to fold\n'))
return 1
- roots = repo.revs('roots(%ld)', revs)
- if len(roots) > 1:
- raise error.Abort(_("cannot fold non-linear revisions "
- "(multiple roots given)"))
- root = repo[roots.first()]
- if root.phase() <= phases.public:
- raise error.Abort(_("cannot fold public revisions"))
- heads = repo.revs('heads(%ld)', revs)
- if len(heads) > 1:
- 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"))
+ root, head = _foldcheck(repo, revs)
+
wlock = lock = None
try:
wlock = repo.wlock()
@@ -3174,7 +3159,25 @@
finally:
lockmod.release(lock, wlock)
-
+def _foldcheck(repo, revs):
+ roots = repo.revs('roots(%ld)', revs)
+ if len(roots) > 1:
+ raise error.Abort(_("cannot fold non-linear revisions "
+ "(multiple roots given)"))
+ root = repo[roots.first()]
+ if root.phase() <= phases.public:
+ raise error.Abort(_("cannot fold public revisions"))
+ heads = repo.revs('heads(%ld)', revs)
+ if len(heads) > 1:
+ 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"))
+ return root, head
@eh.wrapcommand('graft')
def graftwrapper(orig, ui, repo, *revs, **kwargs):