diff -r 119e1c6be1ce -r 96f43981c1c4 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Wed Aug 09 17:01:21 2017 +0200 +++ b/mercurial/cmdutil.py Thu Aug 03 05:12:35 2017 +0530 @@ -573,6 +573,111 @@ return finalrs +def _commentlines(raw): + '''Surround lineswith a comment char and a new line''' + lines = raw.splitlines() + commentedlines = ['# %s' % line for line in lines] + return '\n'.join(commentedlines) + '\n' + +def _conflictsmsg(repo): + # avoid merge cycle + from . import merge as mergemod + mergestate = mergemod.mergestate.read(repo) + if not mergestate.active(): + return + + m = scmutil.match(repo[None]) + unresolvedlist = [f for f in mergestate if m(f) and mergestate[f] == 'u'] + if unresolvedlist: + mergeliststr = '\n'.join( + [' %s' % os.path.relpath( + os.path.join(repo.root, path), + pycompat.getcwd()) for path in unresolvedlist]) + msg = _('''Unresolved merge conflicts: + +%s + +To mark files as resolved: hg resolve --mark FILE''') % mergeliststr + else: + msg = _('No unresolved merge conflicts.') + + return _commentlines(msg) + +def _helpmessage(continuecmd, abortcmd): + msg = _('To continue: %s\n' + 'To abort: %s') % (continuecmd, abortcmd) + return _commentlines(msg) + +def _rebasemsg(): + return _helpmessage('hg rebase --continue', 'hg rebase --abort') + +def _histeditmsg(): + return _helpmessage('hg histedit --continue', 'hg histedit --abort') + +def _unshelvemsg(): + return _helpmessage('hg unshelve --continue', 'hg unshelve --abort') + +def _updatecleanmsg(dest=None): + warning = _('warning: this will discard uncommitted changes') + return 'hg update --clean %s (%s)' % (dest or '.', warning) + +def _graftmsg(): + # tweakdefaults requires `update` to have a rev hence the `.` + return _helpmessage('hg graft --continue', _updatecleanmsg()) + +def _mergemsg(): + # tweakdefaults requires `update` to have a rev hence the `.` + return _helpmessage('hg commit', _updatecleanmsg()) + +def _bisectmsg(): + 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') + return _commentlines(msg) + +def fileexistspredicate(filename): + return lambda repo: repo.vfs.exists(filename) + +def _mergepredicate(repo): + return len(repo[None].parents()) > 1 + +STATES = ( + # (state, predicate to detect states, helpful message function) + ('histedit', fileexistspredicate('histedit-state'), _histeditmsg), + ('bisect', fileexistspredicate('bisect.state'), _bisectmsg), + ('graft', fileexistspredicate('graftstate'), _graftmsg), + ('unshelve', fileexistspredicate('unshelverebasestate'), _unshelvemsg), + ('rebase', fileexistspredicate('rebasestate'), _rebasemsg), + # The merge state is part of a list that will be iterated over. + # They need to be last because some of the other unfinished states may also + # be in a merge or update state (eg. rebase, histedit, graft, etc). + # We want those to have priority. + ('merge', _mergepredicate, _mergemsg), +) + +def _getrepostate(repo): + # experimental config: commands.status.skipstates + skip = set(repo.ui.configlist('commands', 'status.skipstates')) + for state, statedetectionpredicate, msgfn in STATES: + if state in skip: + continue + if statedetectionpredicate(repo): + return (state, statedetectionpredicate, msgfn) + +def morestatus(repo, fm): + statetuple = _getrepostate(repo) + label = 'status.morestatus' + if statetuple: + fm.startitem() + state, statedetectionpredicate, helpfulmsg = statetuple + statemsg = _('The repository is in an unfinished *%s* state.') % state + fm.write('statemsg', '%s\n', _commentlines(statemsg), label=label) + conmsg = _conflictsmsg(repo) + fm.write('conflictsmsg', '%s\n', conmsg, label=label) + if helpfulmsg: + helpmsg = helpfulmsg() + fm.write('helpmsg', '%s\n', helpmsg, label=label) + def findpossible(cmd, table, strict=False): """ Return cmd -> (aliases, command table entry)