author | Matt Mackall <mpm@selenic.com> |
Thu, 27 Dec 2007 23:55:40 -0600 | |
changeset 5733 | 47ec288456bb |
parent 5732 | 2060cad9fabd |
child 5734 | 944b231fa0e7 |
permissions | -rw-r--r-- |
1855
0ba9dee8cfbd
Fixed spacing/indentation, removed #! script header, added short description.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1854
diff
changeset
|
1 |
# bisect extension for mercurial |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
1861
65949d1c9bf7
Added copyright information to hbisect.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1856
diff
changeset
|
3 |
# Copyright 2005, 2006 Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
65949d1c9bf7
Added copyright information to hbisect.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1856
diff
changeset
|
4 |
# 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
|
5 |
# |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
7 |
# of the GNU General Public License, incorporated herein by reference. |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
8 |
|
3891 | 9 |
from mercurial.i18n import _ |
5731
19691160d7f5
bisect: remove unused imports
Matt Mackall <mpm@selenic.com>
parents:
5730
diff
changeset
|
10 |
from mercurial import hg, util, cmdutil |
19691160d7f5
bisect: remove unused imports
Matt Mackall <mpm@selenic.com>
parents:
5730
diff
changeset
|
11 |
import os, array |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
12 |
|
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1367
diff
changeset
|
13 |
class bisect(object): |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
14 |
"""dichotomic search in the DAG of changesets""" |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
15 |
def __init__(self, ui, repo): |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
16 |
self.repo = repo |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
17 |
self.ui = ui |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
18 |
self.goodnodes = [] |
5733 | 19 |
self.skipnodes = [] |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
20 |
self.badnode = None |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
21 |
|
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
22 |
p = self.repo.join("bisect.state") |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
23 |
if os.path.exists(p): |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
24 |
for l in self.repo.opener("bisect.state"): |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
25 |
type, node = l[:-1].split() |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
26 |
node = self.repo.lookup(node) |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
27 |
if type == "good": |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
28 |
self.goodnodes.append(node) |
5733 | 29 |
elif type == "skip": |
30 |
self.skipnodes.append(node) |
|
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
31 |
elif type == "bad": |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
32 |
self.badnode = node |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
33 |
|
2735
07026da25ed8
hbisect.py: don't rely on __del__ to write the current state.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2348
diff
changeset
|
34 |
def write(self): |
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
35 |
f = self.repo.opener("bisect.state", "w") |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
36 |
for n in self.goodnodes: |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
37 |
f.write("good %s\n" % hg.hex(n)) |
5733 | 38 |
for n in self.skipnodes: |
39 |
f.write("skip %s\n" % hg.hex(n)) |
|
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
40 |
if self.badnode: |
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
41 |
f.write("bad %s\n" % hg.hex(self.badnode)) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
42 |
|
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
43 |
def init(self): |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
44 |
"""start a new bisection""" |
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
45 |
p = self.repo.join("bisect.state") |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
46 |
if os.path.exists(p): |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
47 |
os.unlink(p) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
48 |
|
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
49 |
def bisect(self): |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
50 |
cl = self.repo.changelog |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
51 |
clparents = cl.parentrevs |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
52 |
bad = self.badnode |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
53 |
badrev = cl.rev(bad) |
5719
7edf0501f643
bisect: remove usage of sets
Matt Mackall <mpm@selenic.com>
parents:
5718
diff
changeset
|
54 |
|
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
55 |
if not bad: |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
56 |
raise util.Abort(_("You should give at least one bad revision")) |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
57 |
if not self.goodnodes: |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
58 |
self.ui.warn(_("No good revision given\n")) |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
59 |
self.ui.warn(_("Marking the first revision as good\n")) |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
60 |
|
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
61 |
# build ancestors array |
5726
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
62 |
ancestors = [[]] * (cl.count() + 1) # an extra for [-1] |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
63 |
|
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
64 |
# clear goodnodes from array |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
65 |
for good in self.goodnodes: |
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
66 |
ancestors[cl.rev(good)] = None |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
67 |
for rev in xrange(cl.count(), -1, -1): |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
68 |
if ancestors[rev] is None: |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
69 |
for prev in clparents(rev): |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
70 |
ancestors[prev] = None |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
71 |
|
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
72 |
if ancestors[badrev] is None: |
4481
50a46ae14efb
hbisect: fix a typo in error message
TK Soh <teekaysoh@yahoo.com>
parents:
3643
diff
changeset
|
73 |
raise util.Abort(_("Inconsistent state, %s:%s is good and bad") |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
74 |
% (badrev, hg.short(bad))) |
5720
bd86c9f2f697
bisect: inline num_children function
Matt Mackall <mpm@selenic.com>
parents:
5719
diff
changeset
|
75 |
|
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
76 |
# accumulate ancestor lists |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
77 |
for rev in xrange(badrev + 1): |
5726
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
78 |
if ancestors[rev] == []: |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
79 |
p1, p2 = clparents(rev) |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
80 |
a1, a2 = ancestors[p1], ancestors[p2] |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
81 |
if a1: |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
82 |
if a2: |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
83 |
# merge ancestor lists |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
84 |
a = dict.fromkeys(a2) |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
85 |
a.update(dict.fromkeys(a1)) |
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
86 |
a[rev] = None |
5727
1325ebc29e29
bisect: use array.array rather than lists for ancestor lists
Matt Mackall <mpm@selenic.com>
parents:
5726
diff
changeset
|
87 |
ancestors[rev] = array.array("l", a.keys()) |
5726
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
88 |
else: |
5727
1325ebc29e29
bisect: use array.array rather than lists for ancestor lists
Matt Mackall <mpm@selenic.com>
parents:
5726
diff
changeset
|
89 |
ancestors[rev] = a1 + array.array("l", [rev]) |
5726
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
90 |
elif a2: |
5727
1325ebc29e29
bisect: use array.array rather than lists for ancestor lists
Matt Mackall <mpm@selenic.com>
parents:
5726
diff
changeset
|
91 |
ancestors[rev] = a2 + array.array("l", [rev]) |
5726
19cbe2aea2bc
bisect: switch individual ancestor lists from dict to list
Matt Mackall <mpm@selenic.com>
parents:
5725
diff
changeset
|
92 |
else: |
5727
1325ebc29e29
bisect: use array.array rather than lists for ancestor lists
Matt Mackall <mpm@selenic.com>
parents:
5726
diff
changeset
|
93 |
ancestors[rev] = array.array("l", [rev]) |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
94 |
|
5724
13653ee67859
bisect: greatly simplify the ancestor accumulating loop
Matt Mackall <mpm@selenic.com>
parents:
5723
diff
changeset
|
95 |
if badrev not in ancestors[badrev]: |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
96 |
raise util.Abort(_("Could not find the first bad revision")) |
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
97 |
|
5721
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
98 |
# have we narrowed it down to one entry? |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
99 |
tot = len(ancestors[badrev]) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
100 |
if tot == 1: |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
101 |
self.ui.write(_("The first bad revision is:\n")) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
2875
diff
changeset
|
102 |
displayer = cmdutil.show_changeset(self.ui, self.repo, {}) |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
103 |
displayer.show(changenode=self.badnode) |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
104 |
return None |
5721
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
105 |
|
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
106 |
# find the best node to test |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
107 |
best_rev = None |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
108 |
best_len = -1 |
5733 | 109 |
skip = dict.fromkeys([cl.rev(s) for s in self.skipnodes]) |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
110 |
for n in ancestors[badrev]: |
5733 | 111 |
if n in skip: |
112 |
continue |
|
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
113 |
a = len(ancestors[n]) # number of ancestors |
5724
13653ee67859
bisect: greatly simplify the ancestor accumulating loop
Matt Mackall <mpm@selenic.com>
parents:
5723
diff
changeset
|
114 |
b = tot - a # number of non-ancestors |
5721
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
115 |
value = min(a, b) # how good is this test? |
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
116 |
if value > best_len: |
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
117 |
best_len = value |
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
118 |
best_rev = n |
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
119 |
assert best_rev is not None |
5725
8114d4c915a7
bisect: turn ancestors into an array
Matt Mackall <mpm@selenic.com>
parents:
5724
diff
changeset
|
120 |
best_node = cl.node(best_rev) |
5721
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
121 |
|
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
122 |
# compute the approximate number of remaining tests |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
123 |
nb_tests = 0 |
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
124 |
q, r = divmod(tot, 2) |
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
125 |
while q: |
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
126 |
nb_tests += 1 |
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
127 |
q, r = divmod(q, 2) |
5721
8d63fa48d44a
bisect: clarify some bisection code
Matt Mackall <mpm@selenic.com>
parents:
5720
diff
changeset
|
128 |
|
5723
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
129 |
self.ui.write(_("Testing changeset %s:%s " |
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
130 |
"(%s changesets remaining, ~%s tests)\n") |
e3b09819496b
bisect: switch to rev-based calculation
Matt Mackall <mpm@selenic.com>
parents:
5722
diff
changeset
|
131 |
% (best_rev, hg.short(best_node), tot, nb_tests)) |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
132 |
return best_node |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
133 |
|
5730
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
134 |
def next(self): |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
135 |
"""find and update to the next revision to test""" |
5733 | 136 |
if self.goodnodes and self.badnode: |
137 |
node = self.bisect() |
|
138 |
if node is not None: |
|
139 |
cmdutil.bail_if_changed(self.repo) |
|
140 |
return hg.clean(self.repo, node) |
|
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
141 |
|
5730
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
142 |
def good(self, rev=None): |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
143 |
"""mark revision as good and update to the next revision to test""" |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
144 |
self.goodnodes.append(self.repo.lookup(rev or '.')) |
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
145 |
self.write() |
5733 | 146 |
return self.next() |
147 |
||
148 |
def skip(self, rev=None): |
|
149 |
"""mark revision as skipped and update to the next revision to test""" |
|
150 |
self.skipnodes.append(self.repo.lookup(rev or '.')) |
|
151 |
self.write() |
|
152 |
return self.next() |
|
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
153 |
|
5730
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
154 |
def bad(self, rev=None): |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
155 |
"""mark revision as bad and update to the next revision to test""" |
5722
862239055c2e
bisect: fix up node vs rev naming
Matt Mackall <mpm@selenic.com>
parents:
5721
diff
changeset
|
156 |
self.badnode = self.repo.lookup(rev or '.') |
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
157 |
self.write() |
5733 | 158 |
self.next() |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
159 |
|
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
160 |
def bisect_run(ui, repo, cmd=None, *args): |
5729
73646515c435
bisect: slightly improve the help message
Matt Mackall <mpm@selenic.com>
parents:
5728
diff
changeset
|
161 |
"""Subdivision search of changesets |
4390
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
162 |
|
5729
73646515c435
bisect: slightly improve the help message
Matt Mackall <mpm@selenic.com>
parents:
5728
diff
changeset
|
163 |
This extension helps to find changesets which introduce problems. |
73646515c435
bisect: slightly improve the help message
Matt Mackall <mpm@selenic.com>
parents:
5728
diff
changeset
|
164 |
To use, mark the earliest changeset you know exhibits the problem |
4390
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
165 |
as bad, then mark the latest changeset which is free from the problem |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
166 |
as good. Bisect will update your working directory to a revision for |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
167 |
testing. Once you have performed tests, mark the working directory |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
168 |
as bad or good and bisect will either update to another candidate |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
169 |
changeset or announce that it has found the bad revision. |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
170 |
|
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
171 |
Note: bisect expects bad revisions to be descendants of good revisions. |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
172 |
If you are looking for the point at which a problem was fixed, then make |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
173 |
the problem-free state "bad" and the problematic state "good." |
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
174 |
|
052062b98f26
Flesh out bisect help text
Brendan Cully <brendan@kublai.com>
parents:
3891
diff
changeset
|
175 |
For subcommands see "hg bisect help\" |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
176 |
""" |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
177 |
def help_(cmd=None, *args): |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
178 |
"""show help for a given bisect subcommand or all subcommands""" |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
179 |
cmdtable = bisectcmdtable |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
180 |
if cmd: |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
181 |
doc = cmdtable[cmd][0].__doc__ |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
182 |
synopsis = cmdtable[cmd][2] |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
183 |
ui.write(synopsis + "\n") |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
184 |
ui.write("\n" + doc + "\n") |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
185 |
return |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
186 |
ui.write(_("list of subcommands for the bisect extension\n\n")) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
187 |
cmds = cmdtable.keys() |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
188 |
cmds.sort() |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
189 |
m = max([len(c) for c in cmds]) |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
190 |
for cmd in cmds: |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
191 |
doc = cmdtable[cmd][0].__doc__.splitlines(0)[0].rstrip() |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
192 |
ui.write(" %-*s %s\n" % (m, cmd, doc)) |
1855
0ba9dee8cfbd
Fixed spacing/indentation, removed #! script header, added short description.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1854
diff
changeset
|
193 |
|
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
194 |
b = bisect(ui, repo) |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
195 |
bisectcmdtable = { |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
196 |
"init": (b.init, 0, _("hg bisect init")), |
5730
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
197 |
"bad": (b.bad, 1, _("hg bisect bad [<rev>]")), |
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
198 |
"good": (b.good, 1, _("hg bisect good [<rev>]")), |
5733 | 199 |
"skip": (b.skip, 1, _("hg bisect skip [<rev>]")), |
5730
1542c4ce729b
bisect: rename autobad/good/next
Matt Mackall <mpm@selenic.com>
parents:
5729
diff
changeset
|
200 |
"next": (b.next, 0, _("hg bisect next")), |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
201 |
"help": (help_, 1, _("hg bisect help [<subcommand>]")), |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
202 |
} |
1855
0ba9dee8cfbd
Fixed spacing/indentation, removed #! script header, added short description.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1854
diff
changeset
|
203 |
|
5732
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
204 |
if cmd == "reset": |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
205 |
cmd = "init" |
2060cad9fabd
bisect: simplify state handling and init
Matt Mackall <mpm@selenic.com>
parents:
5731
diff
changeset
|
206 |
|
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
207 |
if not bisectcmdtable.has_key(cmd): |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
208 |
ui.warn(_("bisect: Unknown sub-command\n")) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
209 |
return help_() |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
210 |
if len(args) > bisectcmdtable[cmd][1]: |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
211 |
ui.warn(_("bisect: Too many arguments\n")) |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
212 |
return help_() |
5322
121816063b9a
bisect: remove useless try/except
Patrick Mezard <pmezard@gmail.com>
parents:
5320
diff
changeset
|
213 |
ret = bisectcmdtable[cmd][0](*args) |
121816063b9a
bisect: remove useless try/except
Patrick Mezard <pmezard@gmail.com>
parents:
5320
diff
changeset
|
214 |
return ret |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
215 |
|
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
216 |
cmdtable = { |
2348
1772852d7d14
better ui for the bisect extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2305
diff
changeset
|
217 |
"bisect": (bisect_run, [], _("hg bisect [help|init|reset|next|good|bad]")), |
1367
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
218 |
#"bisect-test": (test, [], "hg bisect-test rev"), |
a7678cbd7c28
bisect extension for mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
219 |
} |