Patchwork D6488: statecheck: added support for unfinishedstates and utilities

login
register
mail settings
Submitter phabricator
Date June 7, 2019, 7:43 a.m.
Message ID <differential-rev-PHID-DREV-g4rtzktr7zavtb2sgi3v-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40341/
State Superseded
Headers show

Comments

phabricator - June 7, 2019, 7:43 a.m.
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




To: taapas1128, #hg-reviewers
Cc: mercurial-devel

Patch

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))