D1044: bisect: add --abort flag
quark (Jun Wu)
phabricator at mercurial-scm.org
Fri Oct 13 00:12:05 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Other commands that support a state usually have an `--abort` flag that
restores the repo state to before the state. Let's add a similar one for
bisect. It will be used in the next patch.
.. feature:: bisect now supports an --abort flag
`hg bisect --abort` will update the working copy back to the place where
the bisect started, in addition to what `hg bisect --reset` does.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D1044
AFFECTED FILES
mercurial/commands.py
mercurial/hbisect.py
CHANGE DETAILS
diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -154,24 +154,27 @@
return None
def load_state(repo):
- state = {'current': [], 'good': [], 'bad': [], 'skip': []}
+ state = {'current': [], 'good': [], 'bad': [], 'skip': [], 'original': []}
for l in repo.vfs.tryreadlines("bisect.state"):
kind, node = l[:-1].split()
node = repo.lookup(node)
if kind not in state:
raise error.Abort(_("unknown bisect kind %s") % kind)
state[kind].append(node)
return state
-
def save_state(repo, state):
f = repo.vfs("bisect.state", "w", atomictemp=True)
with repo.wlock():
for kind in sorted(state):
for node in state[kind]:
f.write("%s %s\n" % (kind, hex(node)))
f.close()
+def stateexists(repo):
+ """return True if bisect state exists, False otherwise"""
+ return repo.vfs.exists("bisect.state")
+
def resetstate(repo):
"""remove any bisect state from the repository"""
if repo.vfs.exists("bisect.state"):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -670,11 +670,14 @@
('s', 'skip', False, _('skip testing changeset')),
('e', 'extend', False, _('extend the bisect range')),
('c', 'command', '', _('use command to check changeset state'), _('CMD')),
- ('U', 'noupdate', False, _('do not update to target'))],
+ ('U', 'noupdate', False, _('do not update to target')),
+ ('', 'abort', False,
+ _('abort bisect and update to the original changeset')),
+ ],
_("[-gbsr] [-U] [-c CMD] [REV]"))
def bisect(ui, repo, rev=None, extra=None, command=None,
reset=None, good=None, bad=None, skip=None, extend=None,
- noupdate=None):
+ noupdate=None, abort=None):
"""subdivision search of changesets
This command helps to find changesets which introduce problems. To
@@ -770,6 +773,7 @@
raise error.Abort(_('incompatible arguments'))
incompatibles = {
+ '--abort': abort,
'--bad': bad,
'--command': bool(command),
'--extend': extend,
@@ -788,8 +792,26 @@
hbisect.resetstate(repo)
return
+ firsttime = not hbisect.stateexists(repo)
state = hbisect.load_state(repo)
+ if abort:
+ if firsttime:
+ raise error.Abort(_('not in a bisect'))
+ cmdutil.checkunfinished(repo)
+ cmdutil.bailifchanged(repo)
+ if not state['original']:
+ ui.warn(_('warning: unknown original changeset\n'))
+ else:
+ node = state['original'][0]
+ hg.clean(repo, node, show_stats=False)
+ hbisect.resetstate(repo)
+ ui.warn(_('bisect aborted\n'))
+ return
+
+ if firsttime:
+ state['original'] = [repo['.'].node()]
+
# update state
if good or bad or skip:
if rev:
To: quark, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list