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

  • Committer: Jelmer Vernooij
  • Date: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from __future__ import absolute_import
24
24
 
25
25
from .. import osutils
26
 
from ..sixish import (
27
 
    indexbytes,
28
 
    int2byte,
29
 
    range,
30
 
    )
31
26
 
32
27
 
33
28
class _OutputHandler(object):
55
50
        if self.cur_insert_len > 127:
56
51
            raise AssertionError('We cannot insert more than 127 bytes'
57
52
                                 ' at a time.')
58
 
        self.out_lines.append(int2byte(self.cur_insert_len))
 
53
        self.out_lines.append(bytes([self.cur_insert_len]))
59
54
        self.index_lines.append(False)
60
55
        self.out_lines.extend(self.cur_insert_lines)
61
56
        if self.cur_insert_len < self.min_len_to_index:
71
66
        line_len = len(line)
72
67
        for start_index in range(0, line_len, 127):
73
68
            next_len = min(127, line_len - start_index)
74
 
            self.out_lines.append(int2byte(next_len))
 
69
            self.out_lines.append(bytes([next_len]))
75
70
            self.index_lines.append(False)
76
71
            self.out_lines.append(line[start_index:start_index + next_len])
77
72
            # We don't index long lines, because we won't be able to match
262
257
        # Each insert instruction is at most 127 bytes long
263
258
        for start_byte in range(0, insert_length, 127):
264
259
            insert_count = min(insert_length - start_byte, 127)
265
 
            out_lines.append(int2byte(insert_count))
 
260
            out_lines.append(bytes([insert_count]))
266
261
            # Don't index the 'insert' instruction
267
262
            index_lines.append(False)
268
263
            insert = bytes_to_insert[start_byte:start_byte + insert_count]
330
325
    offset = 0
331
326
    val = 0
332
327
    shift = 0
333
 
    bval = indexbytes(data, offset)
 
328
    bval = data[offset]
334
329
    while bval >= 0x80:
335
330
        val |= (bval & 0x7F) << shift
336
331
        shift += 7
337
332
        offset += 1
338
 
        bval = indexbytes(data, offset)
 
333
        bval = data[offset]
339
334
    val |= bval << shift
340
335
    offset += 1
341
336
    return val, offset
350
345
        base_byte = offset & 0xff
351
346
        if base_byte:
352
347
            copy_command |= copy_bit
353
 
            copy_bytes.append(int2byte(base_byte))
 
348
            copy_bytes.append(bytes([base_byte]))
354
349
        offset >>= 8
355
350
    if length is None:
356
351
        raise ValueError("cannot supply a length of None")
365
360
            base_byte = length & 0xff
366
361
            if base_byte:
367
362
                copy_command |= copy_bit
368
 
                copy_bytes.append(int2byte(base_byte))
 
363
                copy_bytes.append(bytes([base_byte]))
369
364
            length >>= 8
370
 
    copy_bytes[0] = int2byte(copy_command)
 
365
    copy_bytes[0] = bytes([copy_command])
371
366
    return b''.join(copy_bytes)
372
367
 
373
368
 
390
385
    offset = 0
391
386
    length = 0
392
387
    if (cmd & 0x01):
393
 
        offset = indexbytes(bytes, pos)
 
388
        offset = bytes[pos]
394
389
        pos += 1
395
390
    if (cmd & 0x02):
396
 
        offset = offset | (indexbytes(bytes, pos) << 8)
 
391
        offset = offset | (bytes[pos] << 8)
397
392
        pos += 1
398
393
    if (cmd & 0x04):
399
 
        offset = offset | (indexbytes(bytes, pos) << 16)
 
394
        offset = offset | (bytes[pos] << 16)
400
395
        pos += 1
401
396
    if (cmd & 0x08):
402
 
        offset = offset | (indexbytes(bytes, pos) << 24)
 
397
        offset = offset | (bytes[pos] << 24)
403
398
        pos += 1
404
399
    if (cmd & 0x10):
405
 
        length = indexbytes(bytes, pos)
 
400
        length = bytes[pos]
406
401
        pos += 1
407
402
    if (cmd & 0x20):
408
 
        length = length | (indexbytes(bytes, pos) << 8)
 
403
        length = length | (bytes[pos] << 8)
409
404
        pos += 1
410
405
    if (cmd & 0x40):
411
 
        length = length | (indexbytes(bytes, pos) << 16)
 
406
        length = length | (bytes[pos] << 16)
412
407
        pos += 1
413
408
    if length == 0:
414
409
        length = 65536
437
432
    lines = []
438
433
    len_delta = len(delta)
439
434
    while pos < len_delta:
440
 
        cmd = indexbytes(delta, pos)
 
435
        cmd = delta[pos]
441
436
        pos += 1
442
437
        if cmd & 0x80:
443
438
            offset, length, pos = decode_copy_instruction(delta, cmd, pos)