This removes afterresolvedstates from state.py and adds
support for it in _statecheck class.
A new flag doesnotcontinue is added to the class to check whether an
operation supports --continue option or not.
Tests remain unchanged.
| durin42 | |
| martinvonz | 
| hg-reviewers | 
This removes afterresolvedstates from state.py and adds
support for it in _statecheck class.
A new flag doesnotcontinue is added to the class to check whether an
operation supports --continue option or not.
Tests remain unchanged.
| Lint Skipped | 
| Unit Tests Skipped | 
| Path | Packages | |||
|---|---|---|---|---|
| M | hgext/histedit.py (6 lines) | |||
| M | hgext/rebase.py (5 lines) | |||
| M | hgext/shelve.py (5 lines) | |||
| M | mercurial/state.py (31 lines) | 
| Commit | Parents | Author | Summary | Date | 
|---|---|---|---|---|
| 15424e33be05 | 7f33be7b9f66 | Taapas Agrawal | Jun 20 2019, 2:10 AM | 
| if state.actions: | if state.actions: | ||||
| # i18n: column positioning for "hg summary" | # i18n: column positioning for "hg summary" | ||||
| ui.write(_('hist: %s (histedit --continue)\n') % | ui.write(_('hist: %s (histedit --continue)\n') % | ||||
| (ui.label(_('%d remaining'), 'histedit.remaining') % | (ui.label(_('%d remaining'), 'histedit.remaining') % | ||||
| len(state.actions))) | len(state.actions))) | ||||
| def extsetup(ui): | def extsetup(ui): | ||||
| cmdutil.summaryhooks.add('histedit', summaryhook) | cmdutil.summaryhooks.add('histedit', summaryhook) | ||||
| statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True) | statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True, | ||||
| statemod.afterresolvedstates.append( | continueflag=True) | ||||
| ['histedit-state', _('hg histedit --continue')]) | |||||
| def uisetup(ui): | def uisetup(ui): | ||||
| #Replace pull with a decorator to provide --rebase option | #Replace pull with a decorator to provide --rebase option | ||||
| entry = extensions.wrapcommand(commands.table, 'pull', pullrebase) | entry = extensions.wrapcommand(commands.table, 'pull', pullrebase) | ||||
| entry[1].append(('', 'rebase', None, | entry[1].append(('', 'rebase', None, | ||||
| _("rebase working directory to branch head"))) | _("rebase working directory to branch head"))) | ||||
| entry[1].append(('t', 'tool', '', | entry[1].append(('t', 'tool', '', | ||||
| _("specify merge tool for rebase"))) | _("specify merge tool for rebase"))) | ||||
| cmdutil.summaryhooks.add('rebase', summaryhook) | cmdutil.summaryhooks.add('rebase', summaryhook) | ||||
| statemod.addunfinished('rebase', fname='rebasestate', stopflag=True) | statemod.addunfinished('rebase', fname='rebasestate', stopflag=True, | ||||
| statemod.afterresolvedstates.append( | continueflag=True) | ||||
| ['rebasestate', _('hg rebase --continue')]) | |||||
| return listcmd(ui, repo, pats, opts) | return listcmd(ui, repo, pats, opts) | ||||
| elif checkopt('patch') or checkopt('stat'): | elif checkopt('patch') or checkopt('stat'): | ||||
| return patchcmds(ui, repo, pats, opts) | return patchcmds(ui, repo, pats, opts) | ||||
| else: | else: | ||||
| return createcmd(ui, repo, pats, opts) | return createcmd(ui, repo, pats, opts) | ||||
| def extsetup(ui): | def extsetup(ui): | ||||
| statemod.addunfinished( | statemod.addunfinished( | ||||
| 'unshelve', fname=shelvedstate._filename, | 'unshelve', fname=shelvedstate._filename, continueflag=True, | ||||
| cmdmsg=_('unshelve already in progress') | cmdmsg=_('unshelve already in progress') | ||||
| ) | ) | ||||
| statemod.afterresolvedstates.append( | |||||
| [shelvedstate._filename, _('hg unshelve --continue')]) | |||||
| histedit, bisect, update etc and check whether such commands | histedit, bisect, update etc and check whether such commands | ||||
| are in an unfinished conditition or not and return appropriate message | are in an unfinished conditition or not and return appropriate message | ||||
| and hint. | and hint. | ||||
| It also has the ability to register and determine the states of any new | It also has the ability to register and determine the states of any new | ||||
| multistep operation or multistep command extension. | multistep operation or multistep command extension. | ||||
| """ | """ | ||||
| def __init__(self, opname, fname, clearable=False, allowcommit=False, | def __init__(self, opname, fname, clearable=False, allowcommit=False, | ||||
| reportonly=False, cmdmsg="", cmdhint="", statushint="", | reportonly=False, continueflag=False, stopflag=False , | ||||
| stopflag=False): | cmdmsg="", cmdhint="", statushint=""): | ||||
| """opname is the name the command or operation | """opname is the name the command or operation | ||||
| fname is the file name in which data should be stored in .hg directory. | fname is the file name in which data should be stored in .hg directory. | ||||
| It is None for merge command. | It is None for merge command. | ||||
| clearable boolean determines whether or not interrupted states can be | clearable boolean determines whether or not interrupted states can be | ||||
| cleared by running `hg update -C .` which in turn deletes the | cleared by running `hg update -C .` which in turn deletes the | ||||
| state file. | state file. | ||||
| allowcommit boolean decides whether commit is allowed during interrupted | allowcommit boolean decides whether commit is allowed during interrupted | ||||
| state or not. | state or not. | ||||
| reportonly flag is used for operations like bisect where we just | reportonly flag is used for operations like bisect where we just | ||||
| need to detect the operation using 'hg status --verbose' | need to detect the operation using 'hg status --verbose' | ||||
| cmdmsg is used to pass a different status message in case standard | cmdmsg is used to pass a different status message in case standard | ||||
| 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 | |||||
| message of the format "abort: cmdname in progress" is not desired. | message of the format "abort: cmdname in progress" is not desired. | ||||
| cmdhint is used to pass a different hint message in case standard | cmdhint is used to pass a different hint message in case standard | ||||
| message of the format "To continue: hg cmdname --continue | message of the format "To continue: hg cmdname --continue | ||||
| To abort: hg cmdname --abort" is not desired. | To abort: hg cmdname --abort" is not desired. | ||||
| status hint is used to pass a different status message in case standard | status hint is used to pass a different status message in case standard | ||||
| message of the format ('To continue: hg cmdname --continue' | message of the format ('To continue: hg cmdname --continue' | ||||
| 'To abort: hg cmdname --abort') is not desired | 'To abort: hg cmdname --abort') is not desired | ||||
| stopflag is a boolean that determines whether or not a command supports | |||||
| --stop flag | |||||
| reportonly flag is used for operations like bisect where we just | reportonly flag is used for operations like bisect where we just | ||||
| need to detect the operation using 'hg status --verbose' | need to detect the operation using 'hg status --verbose' | ||||
| """ | """ | ||||
| self._opname = opname | self._opname = opname | ||||
| self._fname = fname | self._fname = fname | ||||
| self._clearable = clearable | self._clearable = clearable | ||||
| self._allowcommit = allowcommit | self._allowcommit = allowcommit | ||||
| self._cmdhint = cmdhint | self._cmdhint = cmdhint | ||||
| self._statushint = statushint | self._statushint = statushint | ||||
| self._cmdmsg = cmdmsg | self._cmdmsg = cmdmsg | ||||
| self._stopflag = stopflag | self._stopflag = stopflag | ||||
| self._reportonly = reportonly | self._reportonly = reportonly | ||||
| self._continueflag = continueflag | |||||
| def statusmsg(self): | def statusmsg(self): | ||||
| """returns the hint message corresponding to the command for | """returns the hint message corresponding to the command for | ||||
| hg status --verbose | hg status --verbose | ||||
| """ | """ | ||||
| if not self._statushint: | if not self._statushint: | ||||
| hint = (_('To continue: hg %s --continue\n' | hint = (_('To continue: hg %s --continue\n' | ||||
| 'To abort: hg %s --abort') % (self._opname, | 'To abort: hg %s --abort') % (self._opname, | ||||
| return self._cmdhint | return self._cmdhint | ||||
| def msg(self): | def msg(self): | ||||
| """returns the status message corresponding to the command""" | """returns the status message corresponding to the command""" | ||||
| if not self._cmdmsg: | if not self._cmdmsg: | ||||
| return _('%s in progress') % (self._opname) | return _('%s in progress') % (self._opname) | ||||
| return self._cmdmsg | return self._cmdmsg | ||||
| def continuemsg(self): | |||||
| """ returns appropriate continue message corresponding to command""" | |||||
| return _('hg %s --continue') % (self._opname) | |||||
| def isunfinished(self, repo): | def isunfinished(self, repo): | ||||
| """determines whether a multi-step operation is in progress | """determines whether a multi-step operation is in progress | ||||
| or not | or not | ||||
| """ | """ | ||||
| if self._opname == 'merge': | if self._opname == 'merge': | ||||
| return len(repo[None].parents()) > 1 | return len(repo[None].parents()) > 1 | ||||
| else: | else: | ||||
| return repo.vfs.exists(self._fname) | return repo.vfs.exists(self._fname) | ||||
| # A list of statecheck objects for multistep operations like graft. | # A list of statecheck objects for multistep operations like graft. | ||||
| _unfinishedstates = [] | _unfinishedstates = [] | ||||
| def addunfinished(opname, **kwargs): | def addunfinished(opname, **kwargs): | ||||
| """this registers a new command or operation to unfinishedstates | """this registers a new command or operation to unfinishedstates | ||||
| """ | """ | ||||
| statecheckobj = _statecheck(opname, **kwargs) | statecheckobj = _statecheck(opname, **kwargs) | ||||
| if opname == 'merge': | if opname == 'merge': | ||||
| _unfinishedstates.append(statecheckobj) | _unfinishedstates.append(statecheckobj) | ||||
| else: | else: | ||||
| _unfinishedstates.insert(0, statecheckobj) | _unfinishedstates.insert(0, statecheckobj) | ||||
| addunfinished( | addunfinished( | ||||
| 'graft', fname='graftstate', clearable=True, stopflag=True, | '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( | addunfinished( | ||||
| 'update', fname='updatestate', clearable=True, | 'update', fname='updatestate', clearable=True, | ||||
| cmdmsg=_('last update was interrupted'), | cmdmsg=_('last update was interrupted'), | ||||
| cmdhint=_("use 'hg update' to get a consistent checkout"), | cmdhint=_("use 'hg update' to get a consistent checkout"), | ||||
| statushint=_("To continue: hg update") | statushint=_("To continue: hg update") | ||||
| ) | ) | ||||
| addunfinished( | addunfinished( | ||||
| # experimental config: commands.status.skipstates | # experimental config: commands.status.skipstates | ||||
| skip = set(repo.ui.configlist('commands', 'status.skipstates')) | skip = set(repo.ui.configlist('commands', 'status.skipstates')) | ||||
| for state in _unfinishedstates: | for state in _unfinishedstates: | ||||
| if state._opname in skip: | if state._opname in skip: | ||||
| continue | continue | ||||
| if state.isunfinished(repo): | if state.isunfinished(repo): | ||||
| return (state._opname, state.statusmsg()) | return (state._opname, state.statusmsg()) | ||||
| afterresolvedstates = [ | |||||
| ('graftstate', | |||||
| _('hg graft --continue')), | |||||
| ] | |||||
| def howtocontinue(repo): | def howtocontinue(repo): | ||||
| '''Check for an unfinished operation and return the command to finish | '''Check for an unfinished operation and return the command to finish | ||||
| it. | it. | ||||
| afterresolvedstates tuples define a .hg/{file} and the corresponding | afterresolvedstates tuples define a .hg/{file} and the corresponding | ||||
| command needed to finish it. | command needed to finish it. | ||||
| Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is | Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is | ||||
| a boolean. | a boolean. | ||||
| ''' | ''' | ||||
| contmsg = _("continue: %s") | contmsg = _("continue: %s") | ||||
| for f, msg in afterresolvedstates: | for state in _unfinishedstates: | ||||
| if repo.vfs.exists(f): | if not state._continueflag: | ||||
| return contmsg % msg, True | continue | ||||
| if state.isunfinished(repo): | |||||
| return contmsg % state.continuemsg(), True | |||||
| if repo[None].dirty(missing=True, merge=False, branch=False): | if repo[None].dirty(missing=True, merge=False, branch=False): | ||||
| return contmsg % _("hg commit"), False | return contmsg % _("hg commit"), False | ||||
| return None, None | return None, None | ||||