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,64 @@ 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) diff --git a/mercurial/statecheck.py b/mercurial/statecheck.py new file mode 100644 --- /dev/null +++ b/mercurial/statecheck.py @@ -0,0 +1,71 @@ +from __future__ import absolute_import + +from .i18n import _ + +from . import ( + error, + util, +) + +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 _hintmessage(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 _statusmessage(self): + """returns the status message corresponding to the command""" + if self._cmdname == 'update': + hint = _('last update was interrupted') + else: + hint = _('%s in progress') % (self._cmdname) + return hint + + def _mergepredicate(self, repo): + """determines is a merge is in progress or not""" + return len(repo[None].parents()) > 1