mercurial/hbisect.py
author David Soria Parra <davidsp@fb.com>
Thu, 23 Nov 2017 14:11:27 -0800
changeset 35128 fd8b6b183073
parent 30389 e124e83fd159
child 35129 ec25c8275cfa
permissions -rw-r--r--
hbisect: pass repo into hbisect.bisect Pass repo into the bisect function to get more flexibility in what we can call. This will allow us to use revsets to rewrite parts of the ancestor and children calculation in later patches. Test Plan: python run-tests.py test-bisect* Differential Revision: https://phab.mercurial-scm.org/D1497
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5775
2dd202a6e15b bisect: make bisect a built-in command
Matt Mackall <mpm@selenic.com>
parents: 5774
diff changeset
     1
# changelog bisection for mercurial
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
     2
#
5775
2dd202a6e15b bisect: make bisect a built-in command
Matt Mackall <mpm@selenic.com>
parents: 5774
diff changeset
     3
# Copyright 2007 Matt Mackall
1861
65949d1c9bf7 Added copyright information to hbisect.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1856
diff changeset
     4
# Copyright 2005, 2006 Benoit Boissinot <benoit.boissinot@ens-lyon.org>
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     5
#
1861
65949d1c9bf7 Added copyright information to hbisect.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1856
diff changeset
     6
# Inspired by git bisect, extension skeleton taken from mq.py.
65949d1c9bf7 Added copyright information to hbisect.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1856
diff changeset
     7
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8152
diff changeset
     8
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9583
diff changeset
     9
# GNU General Public License version 2 or any later version.
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    10
25952
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    11
from __future__ import absolute_import
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    12
25113
0ca8410ea345 util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents: 23877
diff changeset
    13
import collections
25952
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    14
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    15
from .i18n import _
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    16
from .node import (
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    17
    hex,
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    18
    short,
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    19
)
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    20
from . import (
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    21
    error,
f0ad094db832 hbisect: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25113
diff changeset
    22
)
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    23
35128
fd8b6b183073 hbisect: pass repo into hbisect.bisect
David Soria Parra <davidsp@fb.com>
parents: 30389
diff changeset
    24
def bisect(repo, state):
6858
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    25
    """find the next node (if any) for testing during a bisect search.
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    26
    returns a (nodes, number, good) tuple.
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    27
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    28
    'nodes' is the final result of the bisect if 'number' is 0.
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    29
    Otherwise 'number' indicates the remaining possible candidates for
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    30
    the search and 'nodes' contains the next bisect target.
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    31
    'good' is True if bisect is searching for a first good changeset, False
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    32
    if searching for a first bad one.
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    33
    """
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    34
35128
fd8b6b183073 hbisect: pass repo into hbisect.bisect
David Soria Parra <davidsp@fb.com>
parents: 30389
diff changeset
    35
    changelog = repo.changelog
5737
6c8df073c3ee bisect: remove class
Matt Mackall <mpm@selenic.com>
parents: 5736
diff changeset
    36
    clparents = changelog.parentrevs
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8109
diff changeset
    37
    skip = set([changelog.rev(n) for n in state['skip']])
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    38
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    39
    def buildancestors(bad, good):
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    40
        # only the earliest bad revision matters
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    41
        badrev = min([changelog.rev(n) for n in bad])
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    42
        goodrevs = [changelog.rev(n) for n in good]
9583
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    43
        goodrev = min(goodrevs)
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    44
        # build visit array
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    45
        ancestors = [None] * (len(changelog) + 1) # an extra for [-1]
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    46
14895
a35d6f822e3e hbisect: do not assume that min(good) is an ancestor of min(bad)
Alexander Krauss <krauss@in.tum.de>
parents: 14894
diff changeset
    47
        # set nodes descended from goodrevs
a35d6f822e3e hbisect: do not assume that min(good) is an ancestor of min(bad)
Alexander Krauss <krauss@in.tum.de>
parents: 14894
diff changeset
    48
        for rev in goodrevs:
a35d6f822e3e hbisect: do not assume that min(good) is an ancestor of min(bad)
Alexander Krauss <krauss@in.tum.de>
parents: 14894
diff changeset
    49
            ancestors[rev] = []
18463
07771e233cf1 bisect: use changelog for iteration
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18358
diff changeset
    50
        for rev in changelog.revs(goodrev + 1):
9583
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    51
            for prev in clparents(rev):
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    52
                if ancestors[prev] == []:
0491be4448bf bisect: limit considered set to descendants of first good rev
Matt Mackall <mpm@selenic.com>
parents: 8482
diff changeset
    53
                    ancestors[rev] = []
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    54
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    55
        # clear good revs from array
14894
3db92e3948d5 hbisect: more consistent variable name
Alexander Krauss <krauss@in.tum.de>
parents: 14893
diff changeset
    56
        for rev in goodrevs:
3db92e3948d5 hbisect: more consistent variable name
Alexander Krauss <krauss@in.tum.de>
parents: 14893
diff changeset
    57
            ancestors[rev] = None
18463
07771e233cf1 bisect: use changelog for iteration
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18358
diff changeset
    58
        for rev in changelog.revs(len(changelog), goodrev):
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    59
            if ancestors[rev] is None:
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    60
                for prev in clparents(rev):
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    61
                    ancestors[prev] = None
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    62
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    63
        if ancestors[badrev] is None:
5777
51776e50bc8c bisect: improve tests
Matt Mackall <mpm@selenic.com>
parents: 5776
diff changeset
    64
            return badrev, None
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    65
        return badrev, ancestors
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    66
14215
e5a59d31bb04 hbisect: use real Booleans instead of 0/1
Martin Geisler <mg@aragost.com>
parents: 12067
diff changeset
    67
    good = False
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    68
    badrev, ancestors = buildancestors(state['bad'], state['good'])
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    69
    if not ancestors: # looking for bad to good transition?
14215
e5a59d31bb04 hbisect: use real Booleans instead of 0/1
Martin Geisler <mg@aragost.com>
parents: 12067
diff changeset
    70
        good = True
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    71
        badrev, ancestors = buildancestors(state['good'], state['bad'])
5777
51776e50bc8c bisect: improve tests
Matt Mackall <mpm@selenic.com>
parents: 5776
diff changeset
    72
    bad = changelog.node(badrev)
5776
35ec669cdd43 bisect: handle search for bad to good transitions
Matt Mackall <mpm@selenic.com>
parents: 5775
diff changeset
    73
    if not ancestors: # now we're confused
20094
06ef32c3b4bb bisect: report "both good and bad" as such, not as "not directly related"
Mads Kiilerich <madski@unity3d.com>
parents: 18463
diff changeset
    74
        if (len(state['bad']) == 1 and len(state['good']) == 1 and
06ef32c3b4bb bisect: report "both good and bad" as such, not as "not directly related"
Mads Kiilerich <madski@unity3d.com>
parents: 18463
diff changeset
    75
            state['bad'] != state['good']):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25952
diff changeset
    76
            raise error.Abort(_("starting revisions are not directly related"))
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25952
diff changeset
    77
        raise error.Abort(_("inconsistent state, %s:%s is good and bad")
6217
fe8dbbe9520d Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents: 5777
diff changeset
    78
                         % (badrev, short(bad)))
5723
e3b09819496b bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents: 5722
diff changeset
    79
5768
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    80
    # build children dict
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    81
    children = {}
25113
0ca8410ea345 util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents: 23877
diff changeset
    82
    visit = collections.deque([badrev])
5769
49809f4a38d8 bisect: calculate candidate set while finding children
Matt Mackall <mpm@selenic.com>
parents: 5768
diff changeset
    83
    candidates = []
5768
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    84
    while visit:
16803
107a3270a24a cleanup: use the deque type where appropriate
Bryan O'Sullivan <bryano@fb.com>
parents: 16647
diff changeset
    85
        rev = visit.popleft()
5767
dd5f8ed31057 bisect: propagate ancestor lists directly to children
Matt Mackall <mpm@selenic.com>
parents: 5766
diff changeset
    86
        if ancestors[rev] == []:
5769
49809f4a38d8 bisect: calculate candidate set while finding children
Matt Mackall <mpm@selenic.com>
parents: 5768
diff changeset
    87
            candidates.append(rev)
5767
dd5f8ed31057 bisect: propagate ancestor lists directly to children
Matt Mackall <mpm@selenic.com>
parents: 5766
diff changeset
    88
            for prev in clparents(rev):
5768
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    89
                if prev != -1:
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    90
                    if prev in children:
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    91
                        children[prev].append(rev)
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    92
                    else:
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    93
                        children[prev] = [rev]
78d14403bdc7 bisect: use a dict for children
Matt Mackall <mpm@selenic.com>
parents: 5767
diff changeset
    94
                        visit.append(prev)
5767
dd5f8ed31057 bisect: propagate ancestor lists directly to children
Matt Mackall <mpm@selenic.com>
parents: 5766
diff changeset
    95
5769
49809f4a38d8 bisect: calculate candidate set while finding children
Matt Mackall <mpm@selenic.com>
parents: 5768
diff changeset
    96
    candidates.sort()
5770
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
    97
    # have we narrowed it down to one entry?
6858
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
    98
    # or have all other possible candidates besides 'bad' have been skipped?
5770
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
    99
    tot = len(candidates)
6858
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
   100
    unskipped = [c for c in candidates if (c not in skip) and (c != badrev)]
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
   101
    if tot == 1 or not unskipped:
30389
e124e83fd159 hbisect: avoid shadowing a variable in a list comprehension
Augie Fackler <augie@google.com>
parents: 30126
diff changeset
   102
        return ([changelog.node(c) for c in candidates], 0, good)
7902
afddc32b2b3f bisect: use integer division
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7557
diff changeset
   103
    perfect = tot // 2
5769
49809f4a38d8 bisect: calculate candidate set while finding children
Matt Mackall <mpm@selenic.com>
parents: 5768
diff changeset
   104
5770
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
   105
    # find the best node to test
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
   106
    best_rev = None
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
   107
    best_len = -1
8463
43186df4bb8e bisect: use set instead of dict
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8228
diff changeset
   108
    poison = set()
5769
49809f4a38d8 bisect: calculate candidate set while finding children
Matt Mackall <mpm@selenic.com>
parents: 5768
diff changeset
   109
    for rev in candidates:
5772
4c46636eafe5 bisect: skip calculations on candidates with too many ancestors
Matt Mackall <mpm@selenic.com>
parents: 5771
diff changeset
   110
        if rev in poison:
8482
fc27c91fff2c hbisect: use set.update for bulk updates
Martin Geisler <mg@lazybytes.net>
parents: 8463
diff changeset
   111
            # poison children
fc27c91fff2c hbisect: use set.update for bulk updates
Martin Geisler <mg@lazybytes.net>
parents: 8463
diff changeset
   112
            poison.update(children.get(rev, []))
5772
4c46636eafe5 bisect: skip calculations on candidates with too many ancestors
Matt Mackall <mpm@selenic.com>
parents: 5771
diff changeset
   113
            continue
5773
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   114
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   115
        a = ancestors[rev] or [rev]
5770
f5b858fc8067 bisect: find best node in ancestor collection pass
Matt Mackall <mpm@selenic.com>
parents: 5769
diff changeset
   116
        ancestors[rev] = None
5773
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   117
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   118
        x = len(a) # number of ancestors
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   119
        y = tot - x # number of non-ancestors
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   120
        value = min(x, y) # how good is this test?
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   121
        if value > best_len and rev not in skip:
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   122
            best_len = value
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   123
            best_rev = rev
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   124
            if value == perfect: # found a perfect candidate? quit early
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   125
                break
5772
4c46636eafe5 bisect: skip calculations on candidates with too many ancestors
Matt Mackall <mpm@selenic.com>
parents: 5771
diff changeset
   126
7557
21233de9c053 Circumvent removal of valid bisect candidates due to previously skipped ones
Bernhard Leiner <bleiner@gmail.com>
parents: 7227
diff changeset
   127
        if y < perfect and rev not in skip: # all downhill from here?
8482
fc27c91fff2c hbisect: use set.update for bulk updates
Martin Geisler <mg@lazybytes.net>
parents: 8463
diff changeset
   128
            # poison children
fc27c91fff2c hbisect: use set.update for bulk updates
Martin Geisler <mg@lazybytes.net>
parents: 8463
diff changeset
   129
            poison.update(children.get(rev, []))
5773
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   130
            continue
5772
4c46636eafe5 bisect: skip calculations on candidates with too many ancestors
Matt Mackall <mpm@selenic.com>
parents: 5771
diff changeset
   131
5773
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   132
        for c in children.get(rev, []):
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   133
            if ancestors[c]:
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8109
diff changeset
   134
                ancestors[c] = list(set(ancestors[c] + a))
5773
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   135
            else:
2f6105ab4c54 bisect: merge ancestor lists when pushing to children
Matt Mackall <mpm@selenic.com>
parents: 5772
diff changeset
   136
                ancestors[c] = a + [c]
5734
944b231fa0e7 bisect: move reporting out of core bisect function
Matt Mackall <mpm@selenic.com>
parents: 5733
diff changeset
   137
5737
6c8df073c3ee bisect: remove class
Matt Mackall <mpm@selenic.com>
parents: 5736
diff changeset
   138
    assert best_rev is not None
6c8df073c3ee bisect: remove class
Matt Mackall <mpm@selenic.com>
parents: 5736
diff changeset
   139
    best_node = changelog.node(best_rev)
1367
a7678cbd7c28 bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
   140
6858
8f256bf98219 Add support for multiple possible bisect results (issue1228, issue1182)
Bernhard Leiner <bleiner@gmail.com>
parents: 6217
diff changeset
   141
    return ([best_node], tot, good)
7227
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   142
30066
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   143
def extendrange(repo, state, nodes, good):
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   144
    # bisect is incomplete when it ends on a merge node and
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   145
    # one of the parent was not checked.
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   146
    parents = repo[nodes[0]].parents()
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   147
    if len(parents) > 1:
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   148
        if good:
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   149
            side = state['bad']
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   150
        else:
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   151
            side = state['good']
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   152
        num = len(set(i.node() for i in parents) & set(side))
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   153
        if num == 1:
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   154
            return parents[0].ancestor(parents[1])
5f93737d0ba8 bisect: move the 'extendrange' to the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30065
diff changeset
   155
    return None
7227
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   156
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   157
def load_state(repo):
16647
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 15406
diff changeset
   158
    state = {'current': [], 'good': [], 'bad': [], 'skip': []}
27525
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   159
    for l in repo.vfs.tryreadlines("bisect.state"):
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   160
        kind, node = l[:-1].split()
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   161
        node = repo.lookup(node)
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   162
        if kind not in state:
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   163
            raise error.Abort(_("unknown bisect kind %s") % kind)
cba62f996780 hbisect: use tryreadlines to load state
Bryan O'Sullivan <bos@serpentine.com>
parents: 26587
diff changeset
   164
        state[kind].append(node)
7227
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   165
    return state
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   166
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   167
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   168
def save_state(repo, state):
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 20095
diff changeset
   169
    f = repo.vfs("bisect.state", "w", atomictemp=True)
27853
9b8a5c6ac176 with: use context manager in bisect save_state
Bryan O'Sullivan <bryano@fb.com>
parents: 27525
diff changeset
   170
    with repo.wlock():
18358
93293813d753 bisect: store state sorted
Mads Kiilerich <mads@kiilerich.com>
parents: 17537
diff changeset
   171
        for kind in sorted(state):
7227
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   172
            for node in state[kind]:
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   173
                f.write("%s %s\n" % (kind, hex(node)))
15057
774da7121fc9 atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents: 14895
diff changeset
   174
        f.close()
7227
e1afb50ec2aa bisect: ability to check revision with command
Alexander Solovyov <piranha@piranha.org.ua>
parents: 6861
diff changeset
   175
30065
ee21ed7fc7a2 bisect: extract the 'reset' logic into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27853
diff changeset
   176
def resetstate(repo):
ee21ed7fc7a2 bisect: extract the 'reset' logic into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27853
diff changeset
   177
    """remove any bisect state from the repository"""
ee21ed7fc7a2 bisect: extract the 'reset' logic into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27853
diff changeset
   178
    if repo.vfs.exists("bisect.state"):
ee21ed7fc7a2 bisect: extract the 'reset' logic into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27853
diff changeset
   179
        repo.vfs.unlink("bisect.state")
ee21ed7fc7a2 bisect: extract the 'reset' logic into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27853
diff changeset
   180
30126
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   181
def checkstate(state):
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   182
    """check we have both 'good' and 'bad' to define a range
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   183
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   184
    Raise Abort exception otherwise."""
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   185
    if state['good'] and state['bad']:
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   186
        return True
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   187
    if not state['good']:
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   188
        raise error.Abort(_('cannot bisect (no known good revisions)'))
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   189
    else:
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   190
        raise error.Abort(_('cannot bisect (no known bad revisions)'))
755730fc1e48 bisect: move check_state into the bisect module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30067
diff changeset
   191
15135
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   192
def get(repo, status):
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   193
    """
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   194
    Return a list of revision(s) that match the given status:
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   195
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   196
    - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 16834
diff changeset
   197
    - ``goods``, ``bads``      : csets topologically good/bad
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   198
    - ``range``              : csets taking part in the bisection
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   199
    - ``pruned``             : csets that are goods, bads or skipped
15138
883d28233a4d revset.bisect: add new 'untested' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15137
diff changeset
   200
    - ``untested``           : csets whose fate is yet unknown
15147
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   201
    - ``ignored``            : csets ignored due to DAG topology
16647
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 15406
diff changeset
   202
    - ``current``            : the cset currently being bisected
15135
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   203
    """
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   204
    state = load_state(repo)
16647
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 15406
diff changeset
   205
    if status in ('good', 'bad', 'skip', 'current'):
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 15406
diff changeset
   206
        return map(repo.changelog.rev, state[status])
15135
f19de58af225 revset.bisect: move bisect() code to hbisect.py
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15057
diff changeset
   207
    else:
17493
d057e92dadfc spelling: following
timeless@mozdev.org
parents: 16834
diff changeset
   208
        # In the following sets, we do *not* call 'bisect()' with more
17509
f7767f52e9eb spelling: recursion
timeless@mozdev.org
parents: 17493
diff changeset
   209
        # than one level of recursion, because that can be very, very
15146
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   210
        # time consuming. Instead, we always develop the expression as
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   211
        # much as possible.
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   212
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   213
        # 'range' is all csets that make the bisection:
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   214
        #   - have a good ancestor and a bad descendant, or conversely
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   215
        # that's because the bisection can go either way
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   216
        range = '( bisect(bad)::bisect(good) | bisect(good)::bisect(bad) )'
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   217
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   218
        _t = repo.revs('bisect(good)::bisect(bad)')
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   219
        # The sets of topologically good or bad csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   220
        if len(_t) == 0:
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   221
            # Goods are topologically after bads
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   222
            goods = 'bisect(good)::'    # Pruned good csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   223
            bads  = '::bisect(bad)'     # Pruned bad csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   224
        else:
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   225
            # Goods are topologically before bads
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   226
            goods = '::bisect(good)'    # Pruned good csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   227
            bads  = 'bisect(bad)::'     # Pruned bad csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   228
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   229
        # 'pruned' is all csets whose fate is already known: good, bad, skip
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   230
        skips = 'bisect(skip)'                 # Pruned skipped csets
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   231
        pruned = '( (%s) | (%s) | (%s) )' % (goods, bads, skips)
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   232
15146
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   233
        # 'untested' is all cset that are- in 'range', but not in 'pruned'
b39d85be78a8 hbisect.get: use simpler code with repo.set(), fix 'pruned' set
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15138
diff changeset
   234
        untested = '( (%s) - (%s) )' % (range, pruned)
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   235
15147
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   236
        # 'ignored' is all csets that were not used during the bisection
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   237
        # due to DAG topology, but may however have had an impact.
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 16834
diff changeset
   238
        # E.g., a branch merged between bads and goods, but whose branch-
15147
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   239
        # point is out-side of the range.
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   240
        iba = '::bisect(bad) - ::bisect(good)'  # Ignored bads' ancestors
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   241
        iga = '::bisect(good) - ::bisect(bad)'  # Ignored goods' ancestors
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   242
        ignored = '( ( (%s) | (%s) ) - (%s) )' % (iba, iga, range)
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   243
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   244
        if status == 'range':
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   245
            return repo.revs(range)
15137
91f93dcd72aa revset.bisect: add new 'pruned' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15136
diff changeset
   246
        elif status == 'pruned':
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   247
            return repo.revs(pruned)
15138
883d28233a4d revset.bisect: add new 'untested' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15137
diff changeset
   248
        elif status == 'untested':
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   249
            return repo.revs(untested)
15147
395ca8cd2669 revset.bisect: add 'ignored' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15146
diff changeset
   250
        elif status == 'ignored':
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   251
            return repo.revs(ignored)
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   252
        elif status == "goods":
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   253
            return repo.revs(goods)
15153
fa0a464e4ca5 hbisect: add two new revset descriptions: 'goods' and 'bads'
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15147
diff changeset
   254
        elif status == "bads":
15404
c1eb8398fe82 localrepo: convert various repo.set() users to repo.revs()
Matt Mackall <mpm@selenic.com>
parents: 15308
diff changeset
   255
            return repo.revs(bads)
15136
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   256
        else:
18219c0789ae revset.bisect: add new 'range' set to the bisect keyword
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15135
diff changeset
   257
            raise error.ParseError(_('invalid bisect state'))
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   258
15406
1f677c7e494d bisect: remove superfluous parameter in label()
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15404
diff changeset
   259
def label(repo, node):
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   260
    rev = repo.changelog.rev(node)
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   261
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   262
    # Try explicit sets
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   263
    if rev in get(repo, 'good'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   264
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   265
        return _('good')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   266
    if rev in get(repo, 'bad'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   267
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   268
        return _('bad')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   269
    if rev in get(repo, 'skip'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   270
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   271
        return _('skipped')
16647
14913fcb30c6 bisect: track the current changeset (issue3382)
Bryan O'Sullivan <bryano@fb.com>
parents: 15406
diff changeset
   272
    if rev in get(repo, 'untested') or rev in get(repo, 'current'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   273
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   274
        return _('untested')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   275
    if rev in get(repo, 'ignored'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   276
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   277
        return _('ignored')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   278
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   279
    # Try implicit sets
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   280
    if rev in get(repo, 'goods'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   281
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   282
        return _('good (implicit)')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   283
    if rev in get(repo, 'bads'):
15308
ab341fbb05b1 bisect: add i18n contexts
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15154
diff changeset
   284
        # i18n: bisect changeset status
15154
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   285
        return _('bad (implicit)')
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   286
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   287
    return None
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   288
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   289
def shortlabel(label):
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   290
    if label:
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   291
        return label[0].upper()
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   292
aa2e908c521e hbisect: add functions to return a label for a cset bisection status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 15153
diff changeset
   293
    return None
30067
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   294
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   295
def printresult(ui, repo, state, displayer, nodes, good):
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   296
    if len(nodes) == 1:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   297
        # narrowed it down to a single revision
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   298
        if good:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   299
            ui.write(_("The first good revision is:\n"))
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   300
        else:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   301
            ui.write(_("The first bad revision is:\n"))
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   302
        displayer.show(repo[nodes[0]])
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   303
        extendnode = extendrange(repo, state, nodes, good)
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   304
        if extendnode is not None:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   305
            ui.write(_('Not all ancestors of this changeset have been'
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   306
                       ' checked.\nUse bisect --extend to continue the '
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   307
                       'bisection from\nthe common ancestor, %s.\n')
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   308
                     % extendnode)
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   309
    else:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   310
        # multiple possible revisions
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   311
        if good:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   312
            ui.write(_("Due to skipped revisions, the first "
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   313
                    "good revision could be any of:\n"))
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   314
        else:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   315
            ui.write(_("Due to skipped revisions, the first "
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   316
                    "bad revision could be any of:\n"))
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   317
        for n in nodes:
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   318
            displayer.show(repo[n])
6e88cd060ba2 bisect: move 'printresult' in the 'hbisect' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30066
diff changeset
   319
    displayer.close()