cmdutil: core functionality to block during multistep commands (issue3955) stable
authorMatt Mackall <mpm@selenic.com>
Wed, 24 Jul 2013 23:27:30 -0500
branchstable
changeset 19474 894fd1a7c533
parent 19473 10a0ae668fe6
child 19475 e24531a23ae4
cmdutil: core functionality to block during multistep commands (issue3955) This adds a registration point and check functions that will allow commands to check if multistep operations like an interrupted graft or rebase are in progress before proceeding.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Wed Jul 24 17:39:29 2013 -0400
+++ b/mercurial/cmdutil.py	Wed Jul 24 23:27:30 2013 -0500
@@ -2103,3 +2103,32 @@
 
 # a list of (ui, repo) functions called by commands.summary
 summaryhooks = util.hooks()
+
+# A list of state files kept by multistep operations like graft.
+# Since graft cannot be aborted, it is considered 'clearable' by update.
+# note: bisect is intentionally excluded
+# (state file, clearable, error, hint)
+unfinishedstates = [
+    ('graftstate', True, _('graft in progress'),
+     _("use 'hg graft --continue' or 'hg update' to abort"))
+    ]
+
+def checkunfinished(repo):
+    '''Look for an unfinished multistep operation, like graft, and abort
+    if found. It's probably good to check this right before
+    bailifchanged().
+    '''
+    for f, clearable, msg, hint in unfinishedstates:
+        if repo.vfs.exists(f):
+            raise util.Abort(msg, hint=hint)
+
+def clearunfinished(repo):
+    '''Check for unfinished operations (as above), and clear the ones
+    that are clearable.
+    '''
+    for f, clearable, msg, hint in unfinishedstates:
+        if not clearable and repo.vfs.exists(f):
+            raise util.Abort(msg, hint=hint)
+    for f, clearable, msg, hint in unfinishedstates:
+        if clearable and repo.vfs.exists(f):
+            util.unlink(repo.join(f))