/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/_groupcompress_py.py

  • Committer: Martin
  • Date: 2017-06-09 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6673.
  • Revision ID: gzlist@googlemail.com-20170609163149-liveiasey25480q6
Make InventoryDeltaError use string formatting, and repr for fileids

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
useless stuff.
21
21
"""
22
22
 
23
 
from bzrlib import osutils
 
23
from __future__ import absolute_import
 
24
 
 
25
from . import osutils
 
26
from .sixish import (
 
27
    range,
 
28
    )
24
29
 
25
30
 
26
31
class _OutputHandler(object):
36
41
    def add_copy(self, start_byte, end_byte):
37
42
        # The data stream allows >64kB in a copy, but to match the compiled
38
43
        # code, we will also limit it to a 64kB copy
39
 
        for start_byte in xrange(start_byte, end_byte, 64*1024):
 
44
        for start_byte in range(start_byte, end_byte, 64*1024):
40
45
            num_bytes = min(64*1024, end_byte - start_byte)
41
46
            copy_bytes = encode_copy_instruction(start_byte, num_bytes)
42
47
            self.out_lines.append(copy_bytes)
62
67
        # Flush out anything pending
63
68
        self._flush_insert()
64
69
        line_len = len(line)
65
 
        for start_index in xrange(0, line_len, 127):
 
70
        for start_index in range(0, line_len, 127):
66
71
            next_len = min(127, line_len - start_index)
67
72
            self.out_lines.append(chr(next_len))
68
73
            self.index_lines.append(False)
125
130
            try:
126
131
                matches[line].add(start_idx + idx)
127
132
            except KeyError:
128
 
                matches[line] = set([start_idx + idx])
 
133
                matches[line] = {start_idx + idx}
129
134
 
130
135
    def get_matches(self, line):
131
136
        """Return the lines which match the line in right."""
254
259
        bytes_to_insert = ''.join(new_lines[start_linenum:end_linenum])
255
260
        insert_length = len(bytes_to_insert)
256
261
        # Each insert instruction is at most 127 bytes long
257
 
        for start_byte in xrange(0, insert_length, 127):
 
262
        for start_byte in range(0, insert_length, 127):
258
263
            insert_count = min(insert_length - start_byte, 127)
259
264
            out_lines.append(chr(insert_count))
260
265
            # Don't index the 'insert' instruction
274
279
        num_bytes = stop_byte - first_byte
275
280
        # The data stream allows >64kB in a copy, but to match the compiled
276
281
        # code, we will also limit it to a 64kB copy
277
 
        for start_byte in xrange(first_byte, stop_byte, 64*1024):
 
282
        for start_byte in range(first_byte, stop_byte, 64*1024):
278
283
            num_bytes = min(64*1024, stop_byte - start_byte)
279
284
            copy_bytes = encode_copy_instruction(start_byte, num_bytes)
280
285
            out_lines.append(copy_bytes)
412
417
 
413
418
def make_delta(source_bytes, target_bytes):
414
419
    """Create a delta from source to target."""
415
 
    if type(source_bytes) is not str:
 
420
    if not isinstance(source_bytes, str):
416
421
        raise TypeError('source is not a str')
417
 
    if type(target_bytes) is not str:
 
422
    if not isinstance(target_bytes, str):
418
423
        raise TypeError('target is not a str')
419
424
    line_locations = LinesDeltaIndex(osutils.split_lines(source_bytes))
420
425
    delta, _ = line_locations.make_delta(osutils.split_lines(target_bytes),
424
429
 
425
430
def apply_delta(basis, delta):
426
431
    """Apply delta to this object to become new_version_id."""
427
 
    if type(basis) is not str:
 
432
    if not isinstance(basis, str):
428
433
        raise TypeError('basis is not a str')
429
 
    if type(delta) is not str:
 
434
    if not isinstance(delta, str):
430
435
        raise TypeError('delta is not a str')
431
436
    target_length, pos = decode_base128_int(delta)
432
437
    lines = []