Patchwork [5,of,8] bisect: move check_state into the bisect module

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 9, 2016, 8:57 a.m.
Message ID <45469b6da789e8d07251.1476003459@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16976/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Pierre-Yves David - Oct. 9, 2016, 8:57 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1472005520 -7200
#      Wed Aug 24 04:25:20 2016 +0200
# Node ID 45469b6da789e8d07251c49f41cfef45fc3eba3b
# Parent  c0e6a5b2b049385418761b9892096e12afd06237
# EXP-Topic bisect
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.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -835,14 +835,6 @@  def bisect(ui, repo, rev=None, extra=Non
 
     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 @@  def bisect(ui, repo, rev=None, extra=Non
                 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 @@  def bisect(ui, repo, rev=None, extra=Non
         hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
         return
 
-    checkstate(state)
+    hbisect.checkstate(state)
 
     # actually bisect
     nodes, changesets, good = hbisect.bisect(repo.changelog, state)
diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -177,6 +177,17 @@  def resetstate(repo):
     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: