Patchwork D6487: states: created new class to handle multi-step operation states

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

Comments

phabricator - June 7, 2019, 2:25 p.m.
taapas1128 updated this revision to Diff 15367.
taapas1128 retitled this revision from "states: created new class to handle unified states(gsoc-19)" to "states: created new class to handle multi-step operation states".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6487?vs=15362&id=15367

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

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -19,6 +19,8 @@ 
 
 from __future__ import absolute_import
 
+from .i18n import _
+
 from . import (
     error,
     util,
@@ -85,3 +87,66 @@ 
     def exists(self):
         """check whether the state file exists or not"""
         return self._repo.vfs.exists(self.fname)
+
+class statecheck(object):
+    """a utility class that will to deal with multistep operations
+       like graft, histedit, bisect, update etc and check whether such commands
+       are in an unfinished conditition of not and return appropriate message
+       and hint.
+       It also has the ability to register and determine the states of any new
+       multistep operation or multistep command extension.
+    """
+
+    def __init__(self, cmdname, fname, clearable=False, allowcommit=False,
+                 stopflag=False):
+        """cmdname is the name the command
+        fname is the file name in which data should be stored in .hg directory.
+        It is None for merge command.
+        clearable boolean determines whether or not interrupted states can be
+        cleared by running `hg update -C .`
+        allowcommit boolean decides whether commit is allowed during interrupted
+        state or not.
+        stopflag is a boolean that determines whether or not a command supports
+        --stop flag
+        """
+        self.cmdname = cmdname
+        self.fname = fname
+        self.clearable = clearable
+        self.allowcommit = allowcommit
+        self.stopflag = stopflag
+
+    def hint(self):
+        """returns the hint message corresponding to the command"""
+        if self.cmdname == 'bisect':
+            msg = _('To mark the changeset good:    hg bisect --good\n'
+                    'To mark the changeset bad:     hg bisect --bad\n'
+                    'To abort:                      hg bisect --reset\n')
+        elif self.cmdname == 'update':
+            msg = _("use 'hg update' to get a consistent checkout")
+        else:
+            msg = (_('To continue:    hg %s --continue\n'
+                    'To abort:       hg %s --abort') % (self.cmdname,
+                    self.cmdname))
+            if self.stopflag:
+                msg = msg + (_('\nTo stop:        hg %s --stop') %
+                     (self.cmdname))
+        return msg
+
+    def msg(self):
+        """returns the status message corresponding to the command"""
+        if self.cmdname == 'update':
+            return _('last update was interrupted')
+        else:
+            return _('%s in progress') % (self.cmdname)
+
+    def inunfinished(self, repo, mergecheck=False):
+        """determines whether a multi-step operation is in progress
+        or not
+        mergecheck flag helps in determining state specifically for merge
+        """
+        if self.cmdname == 'merge' or mergecheck:
+            return len(repo[None].parents()) > 1
+        else:
+            return repo.vfs.exists(self.fname)
+
+