comparison hgext/hbisect.py @ 5734:944b231fa0e7

bisect: move reporting out of core bisect function
author Matt Mackall <mpm@selenic.com>
date Thu, 27 Dec 2007 23:55:40 -0600
parents 47ec288456bb
children 9079081b8982
comparison
equal deleted inserted replaced
5733:47ec288456bb 5734:944b231fa0e7
49 def bisect(self): 49 def bisect(self):
50 cl = self.repo.changelog 50 cl = self.repo.changelog
51 clparents = cl.parentrevs 51 clparents = cl.parentrevs
52 bad = self.badnode 52 bad = self.badnode
53 badrev = cl.rev(bad) 53 badrev = cl.rev(bad)
54
55 if not bad:
56 raise util.Abort(_("You should give at least one bad revision"))
57 if not self.goodnodes:
58 self.ui.warn(_("No good revision given\n"))
59 self.ui.warn(_("Marking the first revision as good\n"))
60 54
61 # build ancestors array 55 # build ancestors array
62 ancestors = [[]] * (cl.count() + 1) # an extra for [-1] 56 ancestors = [[]] * (cl.count() + 1) # an extra for [-1]
63 57
64 # clear goodnodes from array 58 # clear goodnodes from array
96 raise util.Abort(_("Could not find the first bad revision")) 90 raise util.Abort(_("Could not find the first bad revision"))
97 91
98 # have we narrowed it down to one entry? 92 # have we narrowed it down to one entry?
99 tot = len(ancestors[badrev]) 93 tot = len(ancestors[badrev])
100 if tot == 1: 94 if tot == 1:
101 self.ui.write(_("The first bad revision is:\n")) 95 return (self.badnode, 0)
102 displayer = cmdutil.show_changeset(self.ui, self.repo, {})
103 displayer.show(changenode=self.badnode)
104 return None
105 96
106 # find the best node to test 97 # find the best node to test
107 best_rev = None 98 best_rev = None
108 best_len = -1 99 best_len = -1
109 skip = dict.fromkeys([cl.rev(s) for s in self.skipnodes]) 100 skip = dict.fromkeys([cl.rev(s) for s in self.skipnodes])
117 best_len = value 108 best_len = value
118 best_rev = n 109 best_rev = n
119 assert best_rev is not None 110 assert best_rev is not None
120 best_node = cl.node(best_rev) 111 best_node = cl.node(best_rev)
121 112
122 # compute the approximate number of remaining tests 113 return (best_node, tot)
123 nb_tests = 0
124 q, r = divmod(tot, 2)
125 while q:
126 nb_tests += 1
127 q, r = divmod(q, 2)
128
129 self.ui.write(_("Testing changeset %s:%s "
130 "(%s changesets remaining, ~%s tests)\n")
131 % (best_rev, hg.short(best_node), tot, nb_tests))
132 return best_node
133 114
134 def next(self): 115 def next(self):
135 """find and update to the next revision to test""" 116 """find and update to the next revision to test"""
136 if self.goodnodes and self.badnode: 117 if self.goodnodes and self.badnode:
137 node = self.bisect() 118 node, changesets = self.bisect()
138 if node is not None: 119
120 if changesets == 0:
121 self.ui.write(_("The first bad revision is:\n"))
122 displayer = cmdutil.show_changeset(self.ui, self.repo, {})
123 displayer.show(changenode=node)
124 elif node is not None:
125 # compute the approximate number of remaining tests
126 tests, size = 0, 2
127 while size <= changesets:
128 tests, size = tests + 1, size * 2
129 rev = self.repo.changelog.rev(node)
130 self.ui.write(_("Testing changeset %s:%s "
131 "(%s changesets remaining, ~%s tests)\n")
132 % (rev, hg.short(node), changesets, tests))
139 cmdutil.bail_if_changed(self.repo) 133 cmdutil.bail_if_changed(self.repo)
140 return hg.clean(self.repo, node) 134 return hg.clean(self.repo, node)
141 135
142 def good(self, rev=None): 136 def good(self, rev=None):
143 """mark revision as good and update to the next revision to test""" 137 """mark revision as good and update to the next revision to test"""
153 147
154 def bad(self, rev=None): 148 def bad(self, rev=None):
155 """mark revision as bad and update to the next revision to test""" 149 """mark revision as bad and update to the next revision to test"""
156 self.badnode = self.repo.lookup(rev or '.') 150 self.badnode = self.repo.lookup(rev or '.')
157 self.write() 151 self.write()
158 self.next() 152 return self.next()
159 153
160 def bisect_run(ui, repo, cmd=None, *args): 154 def bisect_run(ui, repo, cmd=None, *args):
161 """Subdivision search of changesets 155 """Subdivision search of changesets
162 156
163 This extension helps to find changesets which introduce problems. 157 This extension helps to find changesets which introduce problems.