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