Rev 2634: Check the index length is as expected, when we have done preprocessing. in http://people.ubuntu.com/~robertc/baz2.0/index
Robert Collins
robertc at robertcollins.net
Sun Jul 15 05:40:36 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/index
------------------------------------------------------------
revno: 2634
revision-id: robertc at robertcollins.net-20070715044034-121yu86vvyet4akv
parent: robertc at robertcollins.net-20070715043527-ub3bjsi71j9jnzum
committer: Robert Collins <robertc at robertcollins.net>
branch nick: index
timestamp: Sun 2007-07-15 14:40:34 +1000
message:
Check the index length is as expected, when we have done preprocessing.
modified:
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2007-07-15 04:35:27 +0000
+++ b/bzrlib/index.py 2007-07-15 04:40:34 +0000
@@ -111,6 +111,8 @@
# at the cost of table scans for direct lookup, or a second index for
# direct lookup
nodes = sorted(self._nodes.items())
+ # if we do not prepass, we don't know how long it will be up front.
+ expected_bytes = None
# we only need to pre-pass if we have reference lists at all.
if self.reference_lists:
key_offset_info = []
@@ -143,6 +145,7 @@
while 10 ** digits < possible_total_bytes:
digits += 1
possible_total_bytes = non_ref_bytes + total_references*digits
+ expected_bytes = possible_total_bytes + 1 # terminating newline
# resolve key addresses.
key_addresses = {}
for key, non_ref_bytes, total_references in key_offset_info:
@@ -159,6 +162,11 @@
lines.append("%s\0%s\0%s\0%s\n" % (key, absent,
'\t'.join(flattened_references), value))
lines.append('\n')
+ result = StringIO(''.join(lines))
+ if expected_bytes and len(result.getvalue()) != expected_bytes:
+ raise errors.BzrError('Failed index creation. Internal error:'
+ ' mismatched output length and expected length: %d %d' %
+ (len(result.getvalue()), expected_bytes))
return StringIO(''.join(lines))
More information about the bazaar-commits
mailing list