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