bisect: move check_state into the bisect module
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 24 Aug 2016 04:25:20 +0200
changeset 30126 755730fc1e48
parent 30125 3528117c7b4e
child 30127 1ee65f1a11a5
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.
mercurial/commands.py
mercurial/hbisect.py
--- a/mercurial/commands.py	Wed Aug 24 04:23:13 2016 +0200
+++ b/mercurial/commands.py	Wed Aug 24 04:25:20 2016 +0200
@@ -835,14 +835,6 @@
 
     Returns 0 on success.
     """
-    def checkstate(state):
-        if state['good'] and state['bad']:
-            return True
-        if not state['good']:
-            raise error.Abort(_('cannot bisect (no known good revisions)'))
-        else:
-            raise error.Abort(_('cannot bisect (no known bad revisions)'))
-
     # backward compatibility
     if rev in "good bad reset init".split():
         ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
@@ -913,7 +905,7 @@
                 rev = None # clear for future iterations
                 state[transition].append(ctx.node())
                 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition))
-                checkstate(state)
+                hbisect.checkstate(state)
                 # bisect
                 nodes, changesets, bgood = hbisect.bisect(repo.changelog, state)
                 # update to next check
@@ -928,7 +920,7 @@
         hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
         return
 
-    checkstate(state)
+    hbisect.checkstate(state)
 
     # actually bisect
     nodes, changesets, good = hbisect.bisect(repo.changelog, state)
--- a/mercurial/hbisect.py	Wed Aug 24 04:23:13 2016 +0200
+++ b/mercurial/hbisect.py	Wed Aug 24 04:25:20 2016 +0200
@@ -177,6 +177,17 @@
     if repo.vfs.exists("bisect.state"):
         repo.vfs.unlink("bisect.state")
 
+def checkstate(state):
+    """check we have both 'good' and 'bad' to define a range
+
+    Raise Abort exception otherwise."""
+    if state['good'] and state['bad']:
+        return True
+    if not state['good']:
+        raise error.Abort(_('cannot bisect (no known good revisions)'))
+    else:
+        raise error.Abort(_('cannot bisect (no known bad revisions)'))
+
 def get(repo, status):
     """
     Return a list of revision(s) that match the given status: