Patchwork D6488: statecheck: added support for unfinishedstates and utilities

login
register
mail settings
Submitter phabricator
Date June 7, 2019, 2:26 p.m.
Message ID <16eedeab1eb7977a6d4423919c67bbad@localhost.localdomain>
Download mbox | patch
Permalink /patch/40349/
State Not Applicable
Headers show

Comments

phabricator - June 7, 2019, 2:26 p.m.
taapas1128 updated this revision to Diff 15368.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6488?vs=15360&id=15368

REVISION DETAIL
  https://phab.mercurial-scm.org/D6488

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -139,7 +139,7 @@ 
         else:
             return _('%s in progress') % (self.cmdname)
 
-    def inunfinished(self, repo, mergecheck=False):
+    def isunfinished(self, repo, mergecheck=False):
         """determines whether a multi-step operation is in progress
         or not
         mergecheck flag helps in determining state specifically for merge
@@ -149,4 +149,39 @@ 
         else:
             return repo.vfs.exists(self.fname)
 
+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 state.isunfinished(repo):
+            raise error.Abort(state.msg(), hint=state.hint())
+
+    for s in unfinishedstates:
+        if not s.clearable or (commit and s.allowcommit):
+            continue
+        if s.isunfinished(repo):
+            raise error.Abort(s.msg(), hint=s.hint())
+
+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 state.isunfinished(repo):
+            raise error.Abort(state.msg(), hint=state.msg())
+
+    for s in unfinishedstates:
+        if s.clearable and s.isunfinished(repo):
+            util.unlink(repo.vfs.join(s.fname))