50
50
from .static_tuple import StaticTuple
52
52
_HEADER_READV = (0, 200)
53
_OPTION_KEY_ELEMENTS = "key_elements="
55
_OPTION_NODE_REFS = "node_ref_lists="
56
_SIGNATURE = "Bazaar Graph Index 1\n"
53
_OPTION_KEY_ELEMENTS = b"key_elements="
55
_OPTION_NODE_REFS = b"node_ref_lists="
56
_SIGNATURE = b"Bazaar Graph Index 1\n"
59
59
_whitespace_re = re.compile('[\t\n\x0b\x0c\r\x00 ]')
257
257
should be written to disk.
259
259
lines = [_SIGNATURE]
260
lines.append(_OPTION_NODE_REFS + str(self.reference_lists) + '\n')
261
lines.append(_OPTION_KEY_ELEMENTS + str(self._key_length) + '\n')
260
lines.append(b'%s%d\n' % (_OPTION_NODE_REFS, self.reference_lists))
261
lines.append(b'%s%d\n' % (_OPTION_KEY_ELEMENTS, self._key_length))
262
262
key_count = len(self._nodes) - len(self._absent_keys)
263
lines.append(_OPTION_LEN + str(key_count) + '\n')
263
lines.append(b'%s%d\n' % (_OPTION_LEN, key_count))
264
264
prefix_length = sum(len(x) for x in lines)
265
265
# references are byte offsets. To avoid having to do nasty
266
266
# polynomial work to resolve offsets (references to later in the
323
323
for key, non_ref_bytes, total_references in key_offset_info:
324
324
key_addresses[key] = non_ref_bytes + total_references*digits
326
format_string = '%%0%sd' % digits
326
format_string = b'%%0%dd' % digits
327
327
for key, (absent, references, value) in nodes:
328
328
flattened_references = []
329
329
for ref_list in references:
330
330
ref_addresses = []
331
331
for reference in ref_list:
332
332
ref_addresses.append(format_string % key_addresses[reference])
333
flattened_references.append('\r'.join(ref_addresses))
334
string_key = '\x00'.join(key)
335
lines.append("%s\x00%s\x00%s\x00%s\n" % (string_key, absent,
336
'\t'.join(flattened_references), value))
338
result = BytesIO(''.join(lines))
333
flattened_references.append(b'\r'.join(ref_addresses))
334
string_key = b'\x00'.join(key)
335
lines.append(b"%s\x00%s\x00%s\x00%s\n" % (string_key, absent,
336
b'\t'.join(flattened_references), value))
338
result = BytesIO(b''.join(lines))
339
339
if expected_bytes and len(result.getvalue()) != expected_bytes:
340
340
raise errors.BzrError('Failed index creation. Internal error:'
341
341
' mismatched output length and expected length: %d %d' %