comparison mercurial/commands.py @ 30126:755730fc1e48

bisect: move check_state into the bisect module Now that the function is simpler, we resume our quest to move the logic into the bisect module. In the process, we add basic documentation.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 24 Aug 2016 04:25:20 +0200
parents 3528117c7b4e
children 1ee65f1a11a5
comparison
equal deleted inserted replaced
30125:3528117c7b4e 30126:755730fc1e48
833 833
834 See :hg:`help revsets` for more about the `bisect()` keyword. 834 See :hg:`help revsets` for more about the `bisect()` keyword.
835 835
836 Returns 0 on success. 836 Returns 0 on success.
837 """ 837 """
838 def checkstate(state):
839 if state['good'] and state['bad']:
840 return True
841 if not state['good']:
842 raise error.Abort(_('cannot bisect (no known good revisions)'))
843 else:
844 raise error.Abort(_('cannot bisect (no known bad revisions)'))
845
846 # backward compatibility 838 # backward compatibility
847 if rev in "good bad reset init".split(): 839 if rev in "good bad reset init".split():
848 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) 840 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
849 cmd, rev, extra = rev, extra, None 841 cmd, rev, extra = rev, extra, None
850 if cmd == "good": 842 if cmd == "good":
911 transition = "bad" 903 transition = "bad"
912 ctx = scmutil.revsingle(repo, rev, node) 904 ctx = scmutil.revsingle(repo, rev, node)
913 rev = None # clear for future iterations 905 rev = None # clear for future iterations
914 state[transition].append(ctx.node()) 906 state[transition].append(ctx.node())
915 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) 907 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition))
916 checkstate(state) 908 hbisect.checkstate(state)
917 # bisect 909 # bisect
918 nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) 910 nodes, changesets, bgood = hbisect.bisect(repo.changelog, state)
919 # update to next check 911 # update to next check
920 node = nodes[0] 912 node = nodes[0]
921 if not noupdate: 913 if not noupdate:
926 hbisect.save_state(repo, state) 918 hbisect.save_state(repo, state)
927 displayer = cmdutil.show_changeset(ui, repo, {}) 919 displayer = cmdutil.show_changeset(ui, repo, {})
928 hbisect.printresult(ui, repo, state, displayer, nodes, bgood) 920 hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
929 return 921 return
930 922
931 checkstate(state) 923 hbisect.checkstate(state)
932 924
933 # actually bisect 925 # actually bisect
934 nodes, changesets, good = hbisect.bisect(repo.changelog, state) 926 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
935 if extend: 927 if extend:
936 if not changesets: 928 if not changesets: