D6495: statecheck: added functionality for cmdutil.STATES
taapas1128 (Taapas Agrawal)
phabricator at mercurial-scm.org
Sat Jun 8 16:31:43 UTC 2019
taapas1128 updated this revision to Diff 15391.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D6495?vs=15384&id=15391
REVISION DETAIL
https://phab.mercurial-scm.org/D6495
AFFECTED FILES
mercurial/cmdutil.py
mercurial/state.py
tests/test-graft.t
CHANGE DETAILS
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -281,6 +281,7 @@
# To continue: hg graft --continue
# To abort: hg graft --abort
+ # To stop: hg graft --stop
Commit while interrupted should fail:
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -126,6 +126,9 @@
elif self.cmdname == 'transplant':
msg = _('To continue: hg %s --continue\n'
'To abort: hg update') % (self.cmdname)
+ elif self.cmdname == 'merge':
+ msg = _('To continue: hg commit\n'
+ 'To abort: hg %s --abort') % (self.cmdname)
else:
msg = (_('To continue: hg %s --continue\n'
'To abort: hg %s --abort') % (self.cmdname,
@@ -153,10 +156,14 @@
return repo.vfs.exists(self.fname)
unfinishedstates=[]
-unfinishedstates.append(statecheck('graft','graftstate', clearable=True,
- allowcommit=False, stopflag=True))
+unfinishedstates.append(statecheck('graft', 'graftstate', clearable=True,
+ allowcommit=False, stopflag=True))
+unfinishedstates.append(statecheck('bisect', 'bisect.state', clearable=False,
+ allowcommit=True, stopflag=False))
unfinishedstates.append(statecheck('update', 'updatestate', clearable=True,
allowcommit=False, stopflag=False))
+unfinishedstates.append(statecheck('merge', 'None', clearable=False,
+ allowcommit=False, stopflag=False))
def checkunfinished(repo, commit=False):
'''Look for an unfinished multistep operation, like graft, and abort
@@ -166,13 +173,15 @@
# Check for non-clearable states first, so things like rebase will take
# precedence over update.
for state in unfinishedstates:
- if state.clearable or (commit and state.allowcommit):
+ if (state.clearable or (commit and state.allowcommit)
+ or state.cmdname == 'merge'or state.cmdname == 'bisect'):
continue
if state.isunfinished(repo):
raise error.Abort(state.msg(), hint=state.hint())
for s in unfinishedstates:
- if not s.clearable or (commit and s.allowcommit):
+ if (not s.clearable or (commit and s.allowcommit)
+ or s.cmdname == 'merge' or s.cmdname == 'bisect'):
continue
if s.isunfinished(repo):
raise error.Abort(s.msg(), hint=s.hint())
@@ -182,9 +191,34 @@
that are clearable.
'''
for state in unfinishedstates:
+ if (state.cmdname == 'merge' or state.cmdname == 'bisect'):
+ continue
if not state.clearable and state.isunfinished(repo):
raise error.Abort(state.msg(), hint=state.hint())
for s in unfinishedstates:
+ if (state.cmdname == 'merge' or state.cmdname == 'bisect'):
+ continue
if s.clearable and s.isunfinished(repo):
util.unlink(repo.vfs.join(s.fname))
+
+def getrepostate(repo):
+ # experimental config: commands.status.skipstates
+ skip = set(repo.ui.configlist('commands', 'status.skipstates'))
+ for state in unfinishedstates:
+ if (state.cmdname == 'merge' or state.cmdname == 'update' or
+ state.cmdname in skip):
+ continue
+ if state.isunfinished(repo):
+ return (state.cmdname, state.isunfinished(repo),
+ state.hint())
+
+ for s in unfinishedstates:
+ if s.cmdname in skip:
+ continue
+ if s.cmdname == 'update' and s.isunfinished(repo):
+ return (s.cmdname, s.isunfinished(repo),
+ s.hint())
+ if s.cmdname == 'merge' and s.isunfinished(repo):
+ return (s.cmdname, s.isunfinished(repo),
+ s.hint())
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -619,63 +619,8 @@
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 _graftmsg():
- return _helpmessage('hg graft --continue', 'hg graft --abort')
-
-def _mergemsg():
- return _helpmessage('hg commit', 'hg merge --abort')
-
-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('shelvedstate'), _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)
+ statetuple = statemod.getrepostate(repo)
label = 'status.morestatus'
if statetuple:
state, statedetectionpredicate, helpfulmsg = statetuple
@@ -685,8 +630,7 @@
if conmsg:
fm.plain('%s\n' % conmsg, label=label)
if helpfulmsg:
- helpmsg = helpfulmsg()
- fm.plain('%s\n' % helpmsg, label=label)
+ fm.plain('%s\n' % _commentlines(helpfulmsg), label=label)
def findpossible(cmd, table, strict=False):
"""
To: taapas1128, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list