changeset 42533:0231032729c4

statecheck: added support for cmdutil.afterresolvedstates This removes `afterresolvedstates` from `cmdutil` and adds support for it in `_statecheck` class. A new flag `continueflag` is added to the class to check whether an operation supports `--continue` option or not. Tests remain unchanged. Differential Revision: https://phab.mercurial-scm.org/D6551
author Taapas Agrawal <taapas2897@gmail.com>
date Thu, 20 Jun 2019 11:40:08 +0530
parents 12243f15d53e
children faec09d89435
files hgext/histedit.py hgext/rebase.py hgext/shelve.py mercurial/cmdutil.py mercurial/state.py
diffstat 5 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Sun Jun 09 02:12:58 2019 +0530
+++ b/hgext/histedit.py	Thu Jun 20 11:40:08 2019 +0530
@@ -2313,6 +2313,6 @@
 
 def extsetup(ui):
     cmdutil.summaryhooks.add('histedit', summaryhook)
-    statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True)
-    cmdutil.afterresolvedstates.append(
-        ['histedit-state', _('hg histedit --continue')])
+    statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True,
+                            continueflag=True)
+
--- a/hgext/rebase.py	Sun Jun 09 02:12:58 2019 +0530
+++ b/hgext/rebase.py	Thu Jun 20 11:40:08 2019 +0530
@@ -1950,6 +1950,5 @@
     entry[1].append(('t', 'tool', '',
                      _("specify merge tool for rebase")))
     cmdutil.summaryhooks.add('rebase', summaryhook)
-    statemod.addunfinished('rebase', fname='rebasestate', stopflag=True)
-    cmdutil.afterresolvedstates.append(
-        ['rebasestate', _('hg rebase --continue')])
+    statemod.addunfinished('rebase', fname='rebasestate', stopflag=True,
+                            continueflag=True)
--- a/hgext/shelve.py	Sun Jun 09 02:12:58 2019 +0530
+++ b/hgext/shelve.py	Thu Jun 20 11:40:08 2019 +0530
@@ -1141,8 +1141,7 @@
 
 def extsetup(ui):
     statemod.addunfinished(
-        'unshelve', fname=shelvedstate._filename,
+        'unshelve', fname=shelvedstate._filename, continueflag=True,
         cmdmsg=_('unshelve already in progress')
     )
-    cmdutil.afterresolvedstates.append(
-        [shelvedstate._filename, _('hg unshelve --continue')])
+
--- a/mercurial/cmdutil.py	Sun Jun 09 02:12:58 2019 +0530
+++ b/mercurial/cmdutil.py	Thu Jun 20 11:40:08 2019 +0530
@@ -3296,11 +3296,6 @@
         if s._clearable and s.isunfinished(repo):
             util.unlink(repo.vfs.join(s._fname))
 
-afterresolvedstates = [
-    ('graftstate',
-     _('hg graft --continue')),
-    ]
-
 def howtocontinue(repo):
     '''Check for an unfinished operation and return the command to finish
     it.
@@ -3312,9 +3307,11 @@
     a boolean.
     '''
     contmsg = _("continue: %s")
-    for f, msg in afterresolvedstates:
-        if repo.vfs.exists(f):
-            return contmsg % msg, True
+    for state in statemod._unfinishedstates:
+        if not state._continueflag:
+            continue
+        if state.isunfinished(repo):
+            return contmsg % state.continuemsg(), True
     if repo[None].dirty(missing=True, merge=False, branch=False):
         return contmsg % _("hg commit"), False
     return None, None
--- a/mercurial/state.py	Sun Jun 09 02:12:58 2019 +0530
+++ b/mercurial/state.py	Thu Jun 20 11:40:08 2019 +0530
@@ -98,8 +98,8 @@
     """
 
     def __init__(self, opname, fname, clearable=False, allowcommit=False,
-                 reportonly=False, stopflag=False, cmdmsg="", cmdhint="",
-                 statushint=""):
+                 reportonly=False, continueflag=False, stopflag=False ,
+                 cmdmsg="", cmdhint="", statushint=""):
         """opname is the name the command or operation
         fname is the file name in which data should be stored in .hg directory.
         It is None for merge command.
@@ -110,6 +110,8 @@
         state or not.
         reportonly flag is used for operations like bisect where we just
         need to detect the operation using 'hg status --verbose'
+        continueflag is a boolean determines whether or not a command supports
+        `--continue` option or not.
         stopflag is a boolean that determines whether or not a command supports
         --stop flag
         cmdmsg is used to pass a different status message in case standard
@@ -130,6 +132,7 @@
         self._cmdmsg = cmdmsg
         self._stopflag = stopflag
         self._reportonly = reportonly
+        self._continueflag = continueflag
 
     def statusmsg(self):
         """returns the hint message corresponding to the command for
@@ -160,6 +163,10 @@
             return _('%s in progress') % (self._opname)
         return self._cmdmsg
 
+    def continuemsg(self):
+        """ returns appropriate continue message corresponding to command"""
+        return _('hg %s --continue') % (self._opname)
+
     def isunfinished(self, repo):
         """determines whether a multi-step operation is in progress
         or not
@@ -183,7 +190,8 @@
 
 addunfinished(
     'graft', fname='graftstate', clearable=True, stopflag=True,
-    cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop"),
+    continueflag=True,
+    cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
 )
 addunfinished(
     'update', fname='updatestate', clearable=True,