/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.62.1 by Jelmer Vernooij
Lazy load plugin.
1
# Copyright (C) 2006-2011 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.62.1 by Jelmer Vernooij
Lazy load plugin.
16
17
"""bisect command implementations."""
18
6625.4.4 by Jelmer Vernooij
Drop meta file.
19
from __future__ import absolute_import
20
0.62.1 by Jelmer Vernooij
Lazy load plugin.
21
import sys
6656.2.3 by Jelmer Vernooij
Merge trunk.
22
from .controldir import ControlDir
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
23
from . import revision as _mod_revision
24
from .commands import Command
25
from .errors import BzrCommandError
26
from .option import Option
6754.2.3 by Martin
Remove unicode type in more command arguments
27
from .sixish import (
28
    text_type,
29
    )
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
30
from .trace import note
0.62.1 by Jelmer Vernooij
Lazy load plugin.
31
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
32
BISECT_INFO_PATH = "bisect"
33
BISECT_REV_PATH = "bisect_revid"
0.62.1 by Jelmer Vernooij
Lazy load plugin.
34
35
36
class BisectCurrent(object):
37
    """Bisect class for managing the current revision."""
38
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
39
    def __init__(self, controldir, filename=BISECT_REV_PATH):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
40
        self._filename = filename
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
41
        self._controldir = controldir
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
42
        self._branch = self._controldir.open_branch()
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
43
        if self._controldir.control_transport.has(filename):
44
            self._revid = self._controldir.control_transport.get_bytes(
45
                filename).strip()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
46
        else:
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
47
            self._revid = self._branch.last_revision()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
48
49
    def _save(self):
50
        """Save the current revision."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
51
        self._controldir.control_transport.put_bytes(
52
            self._filename, self._revid + "\n")
0.62.1 by Jelmer Vernooij
Lazy load plugin.
53
54
    def get_current_revid(self):
55
        """Return the current revision id."""
56
        return self._revid
57
58
    def get_current_revno(self):
59
        """Return the current revision number as a tuple."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
60
        revdict = self._branch.get_revision_id_to_revno_map()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
61
        return revdict[self.get_current_revid()]
62
63
    def get_parent_revids(self):
64
        """Return the IDs of the current revision's predecessors."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
65
        repo = self._branch.repository
6754.8.4 by Jelmer Vernooij
Use new context stuff.
66
        with repo.lock_read():
67
            retval = repo.get_parent_map([self._revid]).get(self._revid, None)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
68
        return retval
69
70
    def is_merge_point(self):
71
        """Is the current revision a merge point?"""
72
        return len(self.get_parent_revids()) > 1
73
74
    def show_rev_log(self, out = sys.stdout):
75
        """Write the current revision's log entry to a file."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
76
        rev = self._branch.repository.get_revision(self._revid)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
77
        revno = ".".join([str(x) for x in self.get_current_revno()])
78
        out.write("On revision %s (%s):\n%s\n" % (revno, rev.revision_id,
79
                                                  rev.message))
80
81
    def switch(self, revid):
82
        """Switch the current revision to the given revid."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
83
        working = self._controldir.open_workingtree()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
84
        if isinstance(revid, int):
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
85
            revid = self._branch.get_rev_id(revid)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
86
        elif isinstance(revid, list):
87
            revid = revid[0].in_history(working.branch).rev_id
88
        working.revert(None, working.branch.repository.revision_tree(revid),
89
                       False)
90
        self._revid = revid
91
        self._save()
92
93
    def reset(self):
94
        """Revert bisection, setting the working tree to normal."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
95
        working = self._controldir.open_workingtree()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
96
        last_rev = working.branch.last_revision()
97
        rev_tree = working.branch.repository.revision_tree(last_rev)
98
        working.revert(None, rev_tree, False)
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
99
        if self._controldir.control_transport.has(BISECT_REV_PATH):
100
            self._controldir.control_transport.delete(BISECT_REV_PATH)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
101
102
103
class BisectLog(object):
104
    """Bisect log file handler."""
105
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
106
    def __init__(self, controldir, filename=BISECT_INFO_PATH):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
107
        self._items = []
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
108
        self._current = BisectCurrent(controldir)
109
        self._controldir = controldir
110
        self._branch = None
0.62.1 by Jelmer Vernooij
Lazy load plugin.
111
        self._high_revid = None
112
        self._low_revid = None
113
        self._middle_revid = None
114
        self._filename = filename
115
        self.load()
116
117
    def _open_for_read(self):
118
        """Open log file for reading."""
119
        if self._filename:
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
120
            return self._controldir.control_transport.get(self._filename)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
121
        else:
122
            return sys.stdin
123
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
124
    def _load_tree(self):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
125
        """Load bzr information."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
126
        if not self._branch:
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
127
            self._branch = self._controldir.open_branch()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
128
129
    def _find_range_and_middle(self, branch_last_rev = None):
130
        """Find the current revision range, and the midpoint."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
131
        self._load_tree()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
132
        self._middle_revid = None
133
134
        if not branch_last_rev:
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
135
            last_revid = self._branch.last_revision()
0.62.1 by Jelmer Vernooij
Lazy load plugin.
136
        else:
137
            last_revid = branch_last_rev
138
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
139
        repo = self._branch.repository
6754.8.4 by Jelmer Vernooij
Use new context stuff.
140
        with repo.lock_read():
0.63.1 by Thomi Richards
Use graph.iter_lefthand_ancestry instead of repo.iter_reverse_revision_history.
141
            graph = repo.get_graph()
142
            rev_sequence = graph.iter_lefthand_ancestry(last_revid,
143
                (_mod_revision.NULL_REVISION,))
0.62.1 by Jelmer Vernooij
Lazy load plugin.
144
            high_revid = None
145
            low_revid = None
146
            between_revs = []
147
            for revision in rev_sequence:
148
                between_revs.insert(0, revision)
149
                matches = [x[1] for x in self._items
150
                           if x[0] == revision and x[1] in ('yes', 'no')]
151
                if not matches:
152
                    continue
153
                if len(matches) > 1:
154
                    raise RuntimeError("revision %s duplicated" % revision)
155
                if matches[0] == "yes":
156
                    high_revid = revision
157
                    between_revs = []
158
                elif matches[0] == "no":
159
                    low_revid = revision
160
                    del between_revs[0]
161
                    break
162
163
            if not high_revid:
164
                high_revid = last_revid
165
            if not low_revid:
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
166
                low_revid = self._branch.get_rev_id(1)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
167
168
        # The spread must include the high revision, to bias
169
        # odd numbers of intervening revisions towards the high
170
        # side.
171
172
        spread = len(between_revs) + 1
173
        if spread < 2:
174
            middle_index = 0
175
        else:
176
            middle_index = (spread / 2) - 1
177
178
        if len(between_revs) > 0:
179
            self._middle_revid = between_revs[middle_index]
180
        else:
181
            self._middle_revid = high_revid
182
183
        self._high_revid = high_revid
184
        self._low_revid = low_revid
185
186
    def _switch_wc_to_revno(self, revno, outf):
187
        """Move the working tree to the given revno."""
188
        self._current.switch(revno)
189
        self._current.show_rev_log(out=outf)
190
191
    def _set_status(self, revid, status):
192
        """Set the bisect status for the given revid."""
193
        if not self.is_done():
0.63.1 by Thomi Richards
Use graph.iter_lefthand_ancestry instead of repo.iter_reverse_revision_history.
194
            if status != "done" and revid in [x[0] for x in self._items
0.62.1 by Jelmer Vernooij
Lazy load plugin.
195
                                              if x[1] in ['yes', 'no']]:
196
                raise RuntimeError("attempting to add revid %s twice" % revid)
197
            self._items.append((revid, status))
198
199
    def change_file_name(self, filename):
200
        """Switch log files."""
201
        self._filename = filename
202
203
    def load(self):
204
        """Load the bisection log."""
205
        self._items = []
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
206
        if self._controldir.control_transport.has(self._filename):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
207
            revlog = self._open_for_read()
208
            for line in revlog:
209
                (revid, status) = line.split()
210
                self._items.append((revid, status))
211
212
    def save(self):
213
        """Save the bisection log."""
6681.2.8 by Jelmer Vernooij
Remove incorrect b''.
214
        contents = ''.join(
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
215
            ("%s %s\n" % (revid, status))
216
            for (revid, status) in self._items)
217
        if self._filename:
218
            self._controldir.control_transport.put_bytes(
219
                self._filename, contents)
220
        else:
221
            sys.stdout.write(contents)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
222
223
    def is_done(self):
224
        """Report whether we've found the right revision."""
225
        return len(self._items) > 0 and self._items[-1][1] == "done"
226
227
    def set_status_from_revspec(self, revspec, status):
228
        """Set the bisection status for the revision in revspec."""
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
229
        self._load_tree()
230
        revid = revspec[0].in_history(self._branch).rev_id
0.62.1 by Jelmer Vernooij
Lazy load plugin.
231
        self._set_status(revid, status)
232
233
    def set_current(self, status):
234
        """Set the current revision to the given bisection status."""
235
        self._set_status(self._current.get_current_revid(), status)
236
237
    def is_merge_point(self, revid):
238
        return len(self.get_parent_revids(revid)) > 1
239
240
    def get_parent_revids(self, revid):
6681.2.1 by Jelmer Vernooij
Rename more uses of bzrdir to controldir.
241
        repo = self._branch.repository
6754.8.4 by Jelmer Vernooij
Use new context stuff.
242
        with repo.lock_read():
0.62.1 by Jelmer Vernooij
Lazy load plugin.
243
            retval = repo.get_parent_map([revid]).get(revid, None)
244
        return retval
245
246
    def bisect(self, outf):
247
        """Using the current revision's status, do a bisection."""
248
        self._find_range_and_middle()
249
        # If we've found the "final" revision, check for a
250
        # merge point.
251
        while ((self._middle_revid == self._high_revid
252
                or self._middle_revid == self._low_revid)
253
                and self.is_merge_point(self._middle_revid)):
254
            for parent in self.get_parent_revids(self._middle_revid):
255
                if parent == self._low_revid:
256
                    continue
257
                else:
258
                    self._find_range_and_middle(parent)
259
                    break
260
        self._switch_wc_to_revno(self._middle_revid, outf)
261
        if self._middle_revid == self._high_revid or \
262
           self._middle_revid == self._low_revid:
263
            self.set_current("done")
264
265
266
class cmd_bisect(Command):
267
    """Find an interesting commit using a binary search.
268
269
    Bisecting, in a nutshell, is a way to find the commit at which
270
    some testable change was made, such as the introduction of a bug
271
    or feature.  By identifying a version which did not have the
272
    interesting change and a later version which did, a developer
273
    can test for the presence of the change at various points in
274
    the history, eventually ending up at the precise commit when
275
    the change was first introduced.
276
277
    This command uses subcommands to implement the search, each
278
    of which changes the state of the bisection.  The
279
    subcommands are:
280
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
281
    brz bisect start
0.62.1 by Jelmer Vernooij
Lazy load plugin.
282
        Start a bisect, possibly clearing out a previous bisect.
283
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
284
    brz bisect yes [-r rev]
0.62.1 by Jelmer Vernooij
Lazy load plugin.
285
        The specified revision (or the current revision, if not given)
286
        has the characteristic we're looking for,
287
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
288
    brz bisect no [-r rev]
0.62.1 by Jelmer Vernooij
Lazy load plugin.
289
        The specified revision (or the current revision, if not given)
290
        does not have the characteristic we're looking for,
291
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
292
    brz bisect move -r rev
0.62.1 by Jelmer Vernooij
Lazy load plugin.
293
        Switch to a different revision manually.  Use if the bisect
294
        algorithm chooses a revision that is not suitable.  Try to
295
        move as little as possible.
296
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
297
    brz bisect reset
0.62.1 by Jelmer Vernooij
Lazy load plugin.
298
        Clear out a bisection in progress.
299
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
300
    brz bisect log [-o file]
0.62.1 by Jelmer Vernooij
Lazy load plugin.
301
        Output a log of the current bisection to standard output, or
302
        to the specified file.
303
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
304
    brz bisect replay <logfile>
0.62.1 by Jelmer Vernooij
Lazy load plugin.
305
        Replay a previously-saved bisect log, forgetting any bisection
306
        that might be in progress.
307
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
308
    brz bisect run <script>
0.62.1 by Jelmer Vernooij
Lazy load plugin.
309
        Bisect automatically using <script> to determine 'yes' or 'no'.
310
        <script> should exit with:
311
           0 for yes
312
           125 for unknown (like build failed so we could not test)
313
           anything else for no
314
    """
315
316
    takes_args = ['subcommand', 'args*']
317
    takes_options = [Option('output', short_name='o',
6754.2.3 by Martin
Remove unicode type in more command arguments
318
                            help='Write log to this file.', type=text_type),
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
319
                     'revision', 'directory']
0.62.1 by Jelmer Vernooij
Lazy load plugin.
320
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
321
    def _check(self, controldir):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
322
        """Check preconditions for most operations to work."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
323
        if not controldir.control_transport.has(BISECT_INFO_PATH):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
324
            raise BzrCommandError("No bisection in progress.")
325
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
326
    def _set_state(self, controldir, revspec, state):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
327
        """Set the state of the given revspec and bisecting.
328
329
        Returns boolean indicating if bisection is done."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
330
        bisect_log = BisectLog(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
331
        if bisect_log.is_done():
332
            note("No further bisection is possible.\n")
333
            bisect_log._current.show_rev_log(self.outf)
334
            return True
335
336
        if revspec:
337
            bisect_log.set_status_from_revspec(revspec, state)
338
        else:
339
            bisect_log.set_current(state)
340
        bisect_log.bisect(self.outf)
341
        bisect_log.save()
342
        return False
343
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
344
    def run(self, subcommand, args_list, directory='.', revision=None, output=None):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
345
        """Handle the bisect command."""
346
347
        log_fn = None
348
        if subcommand in ('yes', 'no', 'move') and revision:
349
            pass
350
        elif subcommand in ('replay', ) and args_list and len(args_list) == 1:
351
            log_fn = args_list[0]
352
        elif subcommand in ('move', ) and not revision:
353
            raise BzrCommandError(
354
                "The 'bisect move' command requires a revision.")
355
        elif subcommand in ('run', ):
356
            run_script = args_list[0]
357
        elif args_list or revision:
358
            raise BzrCommandError(
359
                "Improper arguments to bisect " + subcommand)
360
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
361
        controldir, _ = ControlDir.open_containing(directory)
362
0.62.1 by Jelmer Vernooij
Lazy load plugin.
363
        # Dispatch.
364
        if subcommand == "start":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
365
            self.start(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
366
        elif subcommand == "yes":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
367
            self.yes(controldir, revision)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
368
        elif subcommand == "no":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
369
            self.no(controldir, revision)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
370
        elif subcommand == "move":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
371
            self.move(controldir, revision)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
372
        elif subcommand == "reset":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
373
            self.reset(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
374
        elif subcommand == "log":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
375
            self.log(controldir, output)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
376
        elif subcommand == "replay":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
377
            self.replay(controldir, log_fn)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
378
        elif subcommand == "run":
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
379
            self.run_bisect(controldir, run_script)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
380
        else:
381
            raise BzrCommandError(
382
                "Unknown bisect command: " + subcommand)
383
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
384
    def reset(self, controldir):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
385
        """Reset the bisect state to no state."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
386
        self._check(controldir)
387
        BisectCurrent(controldir).reset()
388
        controldir.control_transport.delete(BISECT_INFO_PATH)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
389
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
390
    def start(self, controldir):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
391
        """Reset the bisect state, then prepare for a new bisection."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
392
        if controldir.control_transport.has(BISECT_INFO_PATH):
393
            BisectCurrent(controldir).reset()
394
            controldir.control_transport.delete(BISECT_INFO_PATH)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
395
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
396
        bisect_log = BisectLog(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
397
        bisect_log.set_current("start")
398
        bisect_log.save()
399
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
400
    def yes(self, controldir, revspec):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
401
        """Mark that a given revision has the state we're looking for."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
402
        self._set_state(controldir, revspec, "yes")
0.62.1 by Jelmer Vernooij
Lazy load plugin.
403
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
404
    def no(self, controldir, revspec):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
405
        """Mark that a given revision does not have the state we're looking for."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
406
        self._set_state(controldir, revspec, "no")
0.62.1 by Jelmer Vernooij
Lazy load plugin.
407
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
408
    def move(self, controldir, revspec):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
409
        """Move to a different revision manually."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
410
        current = BisectCurrent(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
411
        current.switch(revspec)
412
        current.show_rev_log(out=self.outf)
413
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
414
    def log(self, controldir, filename):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
415
        """Write the current bisect log to a file."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
416
        self._check(controldir)
417
        bisect_log = BisectLog(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
418
        bisect_log.change_file_name(filename)
419
        bisect_log.save()
420
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
421
    def replay(self, controldir, filename):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
422
        """Apply the given log file to a clean state, so the state is
423
        exactly as it was when the log was saved."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
424
        if controldir.control_transport.has(BISECT_INFO_PATH):
425
            BisectCurrent(controldir).reset()
426
            controldir.control_transport.delete(BISECT_INFO_PATH)
427
        bisect_log = BisectLog(controldir, filename)
428
        bisect_log.change_file_name(BISECT_INFO_PATH)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
429
        bisect_log.save()
430
431
        bisect_log.bisect(self.outf)
432
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
433
    def run_bisect(self, controldir, script):
0.62.1 by Jelmer Vernooij
Lazy load plugin.
434
        import subprocess
435
        note("Starting bisect.")
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
436
        self.start(controldir)
0.62.1 by Jelmer Vernooij
Lazy load plugin.
437
        while True:
438
            try:
439
                process = subprocess.Popen(script, shell=True)
440
                process.wait()
441
                retcode = process.returncode
442
                if retcode == 0:
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
443
                    done = self._set_state(controldir, None, 'yes')
0.62.1 by Jelmer Vernooij
Lazy load plugin.
444
                elif retcode == 125:
445
                    break
446
                else:
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
447
                    done = self._set_state(controldir, None, 'no')
0.62.1 by Jelmer Vernooij
Lazy load plugin.
448
                if done:
449
                    break
450
            except RuntimeError:
451
                break