rewriteutil: add a precheck function to validate rewrite beforehand
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 23 Jul 2017 19:35:36 +0200
changeset 2777 7d86d88b2fa8
parent 2776 4dd84054ebbb
child 2778 766b38594ded
rewriteutil: add a precheck function to validate rewrite beforehand For now this only checks for changeset mutability and this is only used by 'checkfold'. We'll expand the checking and usage as we go.
hgext3rd/evolve/rewriteutil.py
--- a/hgext3rd/evolve/rewriteutil.py	Mon Jul 24 04:41:31 2017 +0200
+++ b/hgext3rd/evolve/rewriteutil.py	Sun Jul 23 19:35:36 2017 +0200
@@ -31,6 +31,14 @@
     compat,
 )
 
+def precheck(repo, revs, action='rewrite'):
+    """check if <revs> can be rewritten
+
+    <action> can be used to control the commit message.
+    """
+    if repo.revs('%ld and public()', revs):
+        raise error.Abort(_("cannot %s public revisions") % action)
+
 def bookmarksupdater(repo, oldid, tr):
     """Return a callable update(newid) updating the current bookmark
     and bookmarks bound to oldid to newid.
@@ -54,6 +62,7 @@
 
 def foldcheck(repo, revs):
     """check that <revs> can be folded"""
+    precheck(repo, revs, action='fold')
     roots = repo.revs('roots(%ld)', revs)
     if len(roots) > 1:
         raise error.Abort(_("cannot fold non-linear revisions "