mercurial/state.py
changeset 42531 5bddd2244814
parent 42530 dc3fdd1b5af4
child 42532 12243f15d53e
equal deleted inserted replaced
42530:dc3fdd1b5af4 42531:5bddd2244814
   153 addunfinished(
   153 addunfinished(
   154     'update', fname='updatestate', clearable=True,
   154     'update', fname='updatestate', clearable=True,
   155     cmdmsg=_('last update was interrupted'),
   155     cmdmsg=_('last update was interrupted'),
   156     cmdhint=_("use 'hg update' to get a consistent checkout")
   156     cmdhint=_("use 'hg update' to get a consistent checkout")
   157 )
   157 )
       
   158 
       
   159 def _commentlines(raw):
       
   160     '''Surround lineswith a comment char and a new line'''
       
   161     lines = raw.splitlines()
       
   162     commentedlines = ['# %s' % line for line in lines]
       
   163     return '\n'.join(commentedlines) + '\n'
       
   164 
       
   165 def _helpmessage(continuecmd, abortcmd):
       
   166     msg = _('To continue:    %s\n'
       
   167             'To abort:       %s') % (continuecmd, abortcmd)
       
   168     return _commentlines(msg)
       
   169 
       
   170 def _rebasemsg():
       
   171     return _helpmessage('hg rebase --continue', 'hg rebase --abort')
       
   172 
       
   173 def _histeditmsg():
       
   174     return _helpmessage('hg histedit --continue', 'hg histedit --abort')
       
   175 
       
   176 def _unshelvemsg():
       
   177     return _helpmessage('hg unshelve --continue', 'hg unshelve --abort')
       
   178 
       
   179 def _graftmsg():
       
   180     return _helpmessage('hg graft --continue', 'hg graft --abort')
       
   181 
       
   182 def _mergemsg():
       
   183     return _helpmessage('hg commit', 'hg merge --abort')
       
   184 
       
   185 def _bisectmsg():
       
   186     msg = _('To mark the changeset good:    hg bisect --good\n'
       
   187             'To mark the changeset bad:     hg bisect --bad\n'
       
   188             'To abort:                      hg bisect --reset\n')
       
   189     return _commentlines(msg)
       
   190 
       
   191 def fileexistspredicate(filename):
       
   192     return lambda repo: repo.vfs.exists(filename)
       
   193 
       
   194 def _mergepredicate(repo):
       
   195     return len(repo[None].parents()) > 1
       
   196 
       
   197 STATES = (
       
   198     # (state, predicate to detect states, helpful message function)
       
   199     ('histedit', fileexistspredicate('histedit-state'), _histeditmsg),
       
   200     ('bisect', fileexistspredicate('bisect.state'), _bisectmsg),
       
   201     ('graft', fileexistspredicate('graftstate'), _graftmsg),
       
   202     ('unshelve', fileexistspredicate('shelvedstate'), _unshelvemsg),
       
   203     ('rebase', fileexistspredicate('rebasestate'), _rebasemsg),
       
   204     # The merge state is part of a list that will be iterated over.
       
   205     # They need to be last because some of the other unfinished states may also
       
   206     # be in a merge or update state (eg. rebase, histedit, graft, etc).
       
   207     # We want those to have priority.
       
   208     ('merge', _mergepredicate, _mergemsg),
       
   209 )
       
   210 
       
   211 def getrepostate(repo):
       
   212     # experimental config: commands.status.skipstates
       
   213     skip = set(repo.ui.configlist('commands', 'status.skipstates'))
       
   214     for state, statedetectionpredicate, msgfn in STATES:
       
   215         if state in skip:
       
   216             continue
       
   217         if statedetectionpredicate(repo):
       
   218             return (state, statedetectionpredicate, msgfn)