D6488: statecheck: added support for unfinishedstates and utilities
taapas1128 (Taapas Agrawal)
phabricator at mercurial-scm.org
Fri Jun 7 07:43:02 UTC 2019
taapas1128 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This imports `unfinishedstates`, `checkunfinished()`, and `clearunfinished()`
from `cmdutil.py` and makes it compatible with the new statecheck class.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D6488
AFFECTED FILES
mercurial/statecheck.py
CHANGE DETAILS
diff --git a/mercurial/statecheck.py b/mercurial/statecheck.py
--- a/mercurial/statecheck.py
+++ b/mercurial/statecheck.py
@@ -69,3 +69,41 @@
def _mergepredicate(self, repo):
"""determines is a merge is in progress or not"""
return len(repo[None].parents()) > 1
+
+
+unfinishedstates=[]
+unfinishedstates.append(statecheck('graft','graftstate', clearable=True,
+ allowcommit=False, stopflag=True))
+unfinishedstates.append(statecheck('update', 'updatestate', clearable=True,
+ allowcommit=False, stopflag=False))
+
+def checkunfinished(repo, commit=False):
+ '''Look for an unfinished multistep operation, like graft, and abort
+ if found. It's probably good to check this right before
+ bailifchanged().
+ '''
+ # Check for non-clearable states first, so things like rebase will take
+ # precedence over update.
+ for state in unfinishedstates:
+ if state._clearable or (commit and state._allowcommit):
+ continue
+ if repo.vfs.exists(state._fname):
+ raise error.Abort(state._statusmessage(), hint=state._hintmessage())
+
+ for s in unfinishedstates:
+ if not s._clearable or (commit and s._allowcommit):
+ continue
+ if repo.vfs.exists(s._fname):
+ raise error.Abort(s._statusmessage(), hint=s._hintmessage())
+
+def clearunfinished(repo):
+ '''Check for unfinished operations (as above), and clear the ones
+ that are clearable.
+ '''
+ for state in unfinishedstates:
+ if not state._clearable and repo.vfs.exists(state._fname):
+ raise error.Abort(state._statusmessage(), hint=state._hintmessage())
+
+ for s in unfinishedstates:
+ if s._clearable and repo.vfs.exists(s._fname):
+ util.unlink(repo.vfs.join(s._fname))
To: taapas1128, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list