[PATCH 3 of 9] revset.bisect: move bisect() code to hbisect.py

Yann E. MORIN yann.morin.1998 at anciens.enib.fr
Sun Sep 18 18:31:14 CDT 2011


 mercurial/hbisect.py |  13 ++++++++++++-
 mercurial/revset.py  |   9 +++------
 2 files changed, 15 insertions(+), 7 deletions(-)


# HG changeset patch
# User "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>
# Date 1316211645 -7200
# Node ID bb43c2ca3b27380f5832cb3288a709548ab5fc38
# Parent  1a45d6fdeffab94003a7815d0b5959fa92494f7c
revset.bisect: move bisect() code to hbisect.py

Computing the ranges of csets in the bisection belongs to the hbisect
code. This allows for reusing the status computation from many places,
not only the revset code, but also to later display the bisection status
of a cset...

Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>

diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -8,7 +8,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import os
+import os, error
 from i18n import _
 from node import short, hex
 import util
@@ -154,3 +154,14 @@
     finally:
         wlock.release()
 
+def get(repo, status):
+    """
+    Return a list of revision(s) that match the given status:
+
+    - ``good``, ``bad``, ``skip``: as the names imply
+    """
+    state = load_state(repo)
+    if status in ('good', 'bad', 'skip'):
+        return [repo.changelog.rev(n) for n in state[status]]
+    else:
+        raise error.ParseError(_('invalid bisect state'))
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -237,13 +237,10 @@
 
 def bisect(repo, subset, x):
     """``bisect(string)``
-    Changesets marked in the specified bisect state (good, bad, skip).
+    Changesets marked in the specified bisect status (good, bad, skip).
     """
-    state = getstring(x, _("bisect requires a string")).lower()
-    if state not in ('good', 'bad', 'skip'):
-        raise error.ParseError(_('invalid bisect state'))
-    marked = set(repo.changelog.rev(n) for n in hbisect.load_state(repo)[state])
-    return [r for r in subset if r in marked]
+    status = getstring(x, _("bisect requires a string")).lower()
+    return [r for r in subset if r in hbisect.get(repo, status)]
 
 # Backward-compatibility
 # - no help entry so that we do not advertise it any more


More information about the Mercurial-devel mailing list