/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bisect.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""bisect command implementations."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import sys
20
22
from .controldir import ControlDir
21
23
from . import revision as _mod_revision
22
24
from .commands import Command
23
 
from .errors import CommandError
 
25
from .errors import BzrCommandError
24
26
from .option import Option
 
27
from .sixish import (
 
28
    text_type,
 
29
    )
25
30
from .trace import note
26
31
 
27
32
BISECT_INFO_PATH = "bisect"
44
49
    def _save(self):
45
50
        """Save the current revision."""
46
51
        self._controldir.control_transport.put_bytes(
47
 
            self._filename, self._revid + b"\n")
 
52
            self._filename, self._revid + "\n")
48
53
 
49
54
    def get_current_revid(self):
50
55
        """Return the current revision id."""
52
57
 
53
58
    def get_current_revno(self):
54
59
        """Return the current revision number as a tuple."""
55
 
        return self._branch.revision_id_to_dotted_revno(self._revid)
 
60
        revdict = self._branch.get_revision_id_to_revno_map()
 
61
        return revdict[self.get_current_revid()]
56
62
 
57
63
    def get_parent_revids(self):
58
64
        """Return the IDs of the current revision's predecessors."""
120
126
        if not self._branch:
121
127
            self._branch = self._controldir.open_branch()
122
128
 
123
 
    def _find_range_and_middle(self, branch_last_rev=None):
 
129
    def _find_range_and_middle(self, branch_last_rev = None):
124
130
        """Find the current revision range, and the midpoint."""
125
131
        self._load_tree()
126
132
        self._middle_revid = None
133
139
        repo = self._branch.repository
134
140
        with repo.lock_read():
135
141
            graph = repo.get_graph()
136
 
            rev_sequence = graph.iter_lefthand_ancestry(
137
 
                last_revid, (_mod_revision.NULL_REVISION,))
 
142
            rev_sequence = graph.iter_lefthand_ancestry(last_revid,
 
143
                (_mod_revision.NULL_REVISION,))
138
144
            high_revid = None
139
145
            low_revid = None
140
146
            between_revs = []
167
173
        if spread < 2:
168
174
            middle_index = 0
169
175
        else:
170
 
            middle_index = (spread // 2) - 1
 
176
            middle_index = (spread / 2) - 1
171
177
 
172
178
        if len(between_revs) > 0:
173
179
            self._middle_revid = between_revs[middle_index]
201
207
            revlog = self._open_for_read()
202
208
            for line in revlog:
203
209
                (revid, status) = line.split()
204
 
                self._items.append((revid, status.decode('ascii')))
 
210
                self._items.append((revid, status))
205
211
 
206
212
    def save(self):
207
213
        """Save the bisection log."""
208
 
        contents = b''.join(
209
 
            (b"%s %s\n" % (revid, status.encode('ascii')))
 
214
        contents = ''.join(
 
215
            ("%s %s\n" % (revid, status))
210
216
            for (revid, status) in self._items)
211
217
        if self._filename:
212
218
            self._controldir.control_transport.put_bytes(
242
248
        self._find_range_and_middle()
243
249
        # If we've found the "final" revision, check for a
244
250
        # merge point.
245
 
        while ((self._middle_revid == self._high_revid or
246
 
                self._middle_revid == self._low_revid) and
247
 
                self.is_merge_point(self._middle_revid)):
 
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)):
248
254
            for parent in self.get_parent_revids(self._middle_revid):
249
255
                if parent == self._low_revid:
250
256
                    continue
309
315
 
310
316
    takes_args = ['subcommand', 'args*']
311
317
    takes_options = [Option('output', short_name='o',
312
 
                            help='Write log to this file.', type=str),
 
318
                            help='Write log to this file.', type=text_type),
313
319
                     'revision', 'directory']
314
320
 
315
321
    def _check(self, controldir):
316
322
        """Check preconditions for most operations to work."""
317
323
        if not controldir.control_transport.has(BISECT_INFO_PATH):
318
 
            raise CommandError("No bisection in progress.")
 
324
            raise BzrCommandError("No bisection in progress.")
319
325
 
320
326
    def _set_state(self, controldir, revspec, state):
321
327
        """Set the state of the given revspec and bisecting.
335
341
        bisect_log.save()
336
342
        return False
337
343
 
338
 
    def run(self, subcommand, args_list, directory='.', revision=None,
339
 
            output=None):
 
344
    def run(self, subcommand, args_list, directory='.', revision=None, output=None):
340
345
        """Handle the bisect command."""
341
346
 
342
347
        log_fn = None
345
350
        elif subcommand in ('replay', ) and args_list and len(args_list) == 1:
346
351
            log_fn = args_list[0]
347
352
        elif subcommand in ('move', ) and not revision:
348
 
            raise CommandError(
 
353
            raise BzrCommandError(
349
354
                "The 'bisect move' command requires a revision.")
350
355
        elif subcommand in ('run', ):
351
356
            run_script = args_list[0]
352
357
        elif args_list or revision:
353
 
            raise CommandError(
 
358
            raise BzrCommandError(
354
359
                "Improper arguments to bisect " + subcommand)
355
360
 
356
361
        controldir, _ = ControlDir.open_containing(directory)
373
378
        elif subcommand == "run":
374
379
            self.run_bisect(controldir, run_script)
375
380
        else:
376
 
            raise CommandError(
 
381
            raise BzrCommandError(
377
382
                "Unknown bisect command: " + subcommand)
378
383
 
379
384
    def reset(self, controldir):
397
402
        self._set_state(controldir, revspec, "yes")
398
403
 
399
404
    def no(self, controldir, revspec):
400
 
        """Mark a given revision as wrong."""
 
405
        """Mark that a given revision does not have the state we're looking for."""
401
406
        self._set_state(controldir, revspec, "no")
402
407
 
403
408
    def move(self, controldir, revspec):