/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 bzrlib/_chk_map_py.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import zlib
22
22
import struct
23
23
 
24
 
from ..sixish import bytesintern
25
 
from ..static_tuple import StaticTuple
 
24
from bzrlib.static_tuple import StaticTuple
26
25
 
27
26
_LeafNode = None
28
27
_InternalNode = None
45
44
 
46
45
def _search_key_16(key):
47
46
    """Map the key tuple into a search key string which has 16-way fan out."""
48
 
    return b'\x00'.join([b'%08X' % _crc32(bit) for bit in key])
 
47
    return '\x00'.join(['%08X' % _crc32(bit) for bit in key])
49
48
 
50
49
 
51
50
def _search_key_255(key):
54
53
    We use 255-way because '\n' is used as a delimiter, and causes problems
55
54
    while parsing.
56
55
    """
57
 
    data = b'\x00'.join([struct.pack('>L', _crc32(bit)) for bit in key])
58
 
    return data.replace(b'\n', b'_')
59
 
 
60
 
 
61
 
def _deserialise_leaf_node(data, key, search_key_func=None):
 
56
    bytes = '\x00'.join([struct.pack('>L', _crc32(bit)) for bit in key])
 
57
    return bytes.replace('\n', '_')
 
58
 
 
59
 
 
60
def _deserialise_leaf_node(bytes, key, search_key_func=None):
62
61
    """Deserialise bytes, with key key, into a LeafNode.
63
62
 
64
63
    :param bytes: The bytes of the node.
66
65
    """
67
66
    global _unknown, _LeafNode, _InternalNode
68
67
    if _LeafNode is None:
69
 
        from . import chk_map
 
68
        from bzrlib import chk_map
70
69
        _unknown = chk_map._unknown
71
70
        _LeafNode = chk_map.LeafNode
72
71
        _InternalNode = chk_map.InternalNode
73
72
    result = _LeafNode(search_key_func=search_key_func)
74
73
    # Splitlines can split on '\r' so don't use it, split('\n') adds an
75
74
    # extra '' if the bytes ends in a final newline.
76
 
    lines = data.split(b'\n')
 
75
    lines = bytes.split('\n')
77
76
    trailing = lines.pop()
78
 
    if trailing != b'':
 
77
    if trailing != '':
79
78
        raise AssertionError('We did not have a final newline for %s'
80
79
                             % (key,))
81
80
    items = {}
82
 
    if lines[0] != b'chkleaf:':
 
81
    if lines[0] != 'chkleaf:':
83
82
        raise ValueError("not a serialised leaf node: %r" % bytes)
84
83
    maximum_size = int(lines[1])
85
84
    width = int(lines[2])
88
87
    pos = 5
89
88
    while pos < len(lines):
90
89
        line = prefix + lines[pos]
91
 
        elements = line.split(b'\x00')
 
90
        elements = line.split('\x00')
92
91
        pos += 1
93
92
        if len(elements) != width + 1:
94
93
            raise AssertionError(
97
96
        num_value_lines = int(elements[-1])
98
97
        value_lines = lines[pos:pos+num_value_lines]
99
98
        pos += num_value_lines
100
 
        value = b'\n'.join(value_lines)
 
99
        value = '\n'.join(value_lines)
101
100
        items[StaticTuple.from_sequence(elements[:-1])] = value
102
101
    if len(items) != length:
103
102
        raise AssertionError("item count (%d) mismatch for key %s,"
116
115
    else:
117
116
        result._search_prefix = _unknown
118
117
        result._common_serialised_prefix = prefix
119
 
    if len(data) != result._current_size():
 
118
    if len(bytes) != result._current_size():
120
119
        raise AssertionError('_current_size computed incorrectly')
121
120
    return result
122
121
 
123
122
 
124
 
def _deserialise_internal_node(data, key, search_key_func=None):
 
123
def _deserialise_internal_node(bytes, key, search_key_func=None):
125
124
    global _unknown, _LeafNode, _InternalNode
126
125
    if _InternalNode is None:
127
 
        from . import chk_map
 
126
        from bzrlib import chk_map
128
127
        _unknown = chk_map._unknown
129
128
        _LeafNode = chk_map.LeafNode
130
129
        _InternalNode = chk_map.InternalNode
132
131
    # Splitlines can split on '\r' so don't use it, remove the extra ''
133
132
    # from the result of split('\n') because we should have a trailing
134
133
    # newline
135
 
    lines = data.split(b'\n')
136
 
    if lines[-1] != b'':
 
134
    lines = bytes.split('\n')
 
135
    if lines[-1] != '':
137
136
        raise ValueError("last line must be ''")
138
137
    lines.pop(-1)
139
138
    items = {}
140
 
    if lines[0] != b'chknode:':
 
139
    if lines[0] != 'chknode:':
141
140
        raise ValueError("not a serialised internal node: %r" % bytes)
142
141
    maximum_size = int(lines[1])
143
142
    width = int(lines[2])
145
144
    common_prefix = lines[4]
146
145
    for line in lines[5:]:
147
146
        line = common_prefix + line
148
 
        prefix, flat_key = line.rsplit(b'\x00', 1)
 
147
        prefix, flat_key = line.rsplit('\x00', 1)
149
148
        items[prefix] = StaticTuple(flat_key,)
150
149
    if len(items) == 0:
151
150
        raise AssertionError("We didn't find any item for %s" % key)
162
161
    return result
163
162
 
164
163
 
165
 
def _bytes_to_text_key(data):
 
164
def _bytes_to_text_key(bytes):
166
165
    """Take a CHKInventory value string and return a (file_id, rev_id) tuple"""
167
 
    sections = data.split(b'\n')
168
 
    kind, file_id = sections[0].split(b': ')
169
 
    return (bytesintern(file_id), bytesintern(sections[3]))
 
166
    sections = bytes.split('\n')
 
167
    kind, file_id = sections[0].split(': ')
 
168
    return (intern(file_id), intern(sections[3]))
170
169