Patchwork D6488: statecheck: added support for unfinishedstates and utilities

login
register
mail settings
Submitter phabricator
Date June 7, 2019, 4:06 p.m.
Message ID <fa4c6ba8d829eed15bc956caa5a7309c@localhost.localdomain>
Download mbox | patch
Permalink /patch/40350/
State Not Applicable
Headers show

Comments

phabricator - June 7, 2019, 4:06 p.m.
taapas1128 updated this revision to Diff 15369.

REPOSITORY
  rHG Mercurial

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

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
@@ -123,6 +123,9 @@ 
                     'To abort:                      hg bisect --reset\n')
         elif self.cmdname == 'update':
             msg = _("use 'hg update' to get a consistent checkout")
+        elif self.cmdname == 'transplant':
+                msg = _('To continue:    hg %s --continue\n'
+                        'To abort:       hg update') % (self.cmdname)
         else:
             msg = (_('To continue:    hg %s --continue\n'
                     'To abort:       hg %s --abort') % (self.cmdname,
@@ -139,7 +142,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 +152,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.hint())
+
+    for s in unfinishedstates:
+        if s.clearable and s.isunfinished(repo):
+            util.unlink(repo.vfs.join(s.fname))