~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-27 20:12:12 UTC
  • mto: (3735.39.2 clean)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090327201212-1ykalx15yr1cquxt
Implement make_delta and apply_delta.

Update the permuted tests so that both implementations are tested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
_null_sha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
56
56
 
57
57
 
58
 
def encode_base128_int(val):
59
 
    """Convert an integer into a 7-bit lsb encoding."""
60
 
    bytes = []
61
 
    count = 0
62
 
    while val >= 0x80:
63
 
        bytes.append(chr((val | 0x80) & 0xFF))
64
 
        val >>= 7
65
 
    bytes.append(chr(val))
66
 
    return ''.join(bytes)
67
 
 
68
 
 
69
 
def decode_base128_int(bytes):
70
 
    """Decode an integer from a 7-bit lsb encoding."""
71
 
    offset = 0
72
 
    val = 0
73
 
    shift = 0
74
 
    bval = ord(bytes[offset])
75
 
    while bval >= 0x80:
76
 
        val |= (bval & 0x7F) << shift
77
 
        shift += 7
78
 
        offset += 1
79
 
        bval = ord(bytes[offset])
80
 
    val |= bval << shift
81
 
    offset += 1
82
 
    return val, offset
83
 
 
84
 
 
85
58
def sort_gc_optimal(parent_map):
86
59
    """Sort and group the keys in parent_map into groupcompress order.
87
60
 
784
757
        bytes_length = len(bytes)
785
758
        new_lines = osutils.split_lines(bytes)
786
759
        out_lines, index_lines = self.line_locations.make_delta(new_lines,
787
 
                                                                soft=soft)
788
 
        out_lines[2] = encode_base128_int(bytes_length)
 
760
            bytes_length=bytes_length, soft=soft)
789
761
        delta_length = sum(map(len, out_lines))
790
762
        if delta_length > max_delta_size:
791
763
            # The delta is longer than the fulltext, insert a fulltext
1809
1781
 
1810
1782
from bzrlib._groupcompress_py import (
1811
1783
    apply_delta,
 
1784
    encode_base128_int,
 
1785
    decode_base128_int,
1812
1786
    encode_copy_instruction,
1813
1787
    EquivalenceTable,
1814
1788
    )