Patchwork [3,of,4] bisect: move the 'extendrange' to the 'hbisect' module

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 3, 2016, 2:37 p.m.
Message ID <2c643f89b68448619f6c.1475505439@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16828/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 3, 2016, 2:37 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1472004967 -7200
#      Wed Aug 24 04:16:07 2016 +0200
# Node ID 2c643f89b68448619f6cf4326c58ef8cc686e51a
# Parent  efd8013b1521399d07ca956c1cba7bd9f7dfc6e0
# EXP-Topic bisect
bisect: move the 'extendrange' to the 'hbisect' module

We have a module ready to host any bisect logic. That logic was already isolated
in a function so we just migrate it as is.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -835,20 +835,6 @@  def bisect(ui, repo, rev=None, extra=Non
 
     Returns 0 on success.
     """
-    def extendbisectrange(nodes, good):
-        # bisect is incomplete when it ends on a merge node and
-        # one of the parent was not checked.
-        parents = repo[nodes[0]].parents()
-        if len(parents) > 1:
-            if good:
-                side = state['bad']
-            else:
-                side = state['good']
-            num = len(set(i.node() for i in parents) & set(side))
-            if num == 1:
-                return parents[0].ancestor(parents[1])
-        return None
-
     def print_result(nodes, good):
         displayer = cmdutil.show_changeset(ui, repo, {})
         if len(nodes) == 1:
@@ -858,7 +844,7 @@  def bisect(ui, repo, rev=None, extra=Non
             else:
                 ui.write(_("The first bad revision is:\n"))
             displayer.show(repo[nodes[0]])
-            extendnode = extendbisectrange(nodes, good)
+            extendnode = hbisect.extendrange(repo, state, nodes, good)
             if extendnode is not None:
                 ui.write(_('Not all ancestors of this changeset have been'
                            ' checked.\nUse bisect --extend to continue the '
@@ -977,7 +963,7 @@  def bisect(ui, repo, rev=None, extra=Non
     nodes, changesets, good = hbisect.bisect(repo.changelog, state)
     if extend:
         if not changesets:
-            extendnode = extendbisectrange(nodes, good)
+            extendnode = hbisect.extendrange(repo, state, nodes, good)
             if extendnode is not None:
                 ui.write(_("Extending search to changeset %d:%s\n")
                          % (extendnode.rev(), extendnode))
diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -139,6 +139,19 @@  def bisect(changelog, state):
 
     return ([best_node], tot, good)
 
+def extendrange(repo, state, nodes, good):
+    # bisect is incomplete when it ends on a merge node and
+    # one of the parent was not checked.
+    parents = repo[nodes[0]].parents()
+    if len(parents) > 1:
+        if good:
+            side = state['bad']
+        else:
+            side = state['good']
+        num = len(set(i.node() for i in parents) & set(side))
+        if num == 1:
+            return parents[0].ancestor(parents[1])
+    return None
 
 def load_state(repo):
     state = {'current': [], 'good': [], 'bad': [], 'skip': []}