~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

  • Committer: Robert Collins
  • Date: 2007-07-15 04:40:34 UTC
  • mto: (2592.3.29 repository)
  • mto: This revision was merged to the branch mainline in revision 2624.
  • Revision ID: robertc@robertcollins.net-20070715044034-121yu86vvyet4akv
Check the index length is as expected, when we have done preprocessing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
        # at the cost of table scans for direct lookup, or a second index for
112
112
        # direct lookup
113
113
        nodes = sorted(self._nodes.items())
 
114
        # if we do not prepass, we don't know how long it will be up front.
 
115
        expected_bytes = None
114
116
        # we only need to pre-pass if we have reference lists at all.
115
117
        if self.reference_lists:
116
118
            key_offset_info = []
143
145
            while 10 ** digits < possible_total_bytes:
144
146
                digits += 1
145
147
                possible_total_bytes = non_ref_bytes + total_references*digits
 
148
            expected_bytes = possible_total_bytes + 1 # terminating newline
146
149
            # resolve key addresses.
147
150
            key_addresses = {}
148
151
            for key, non_ref_bytes, total_references in key_offset_info:
159
162
            lines.append("%s\0%s\0%s\0%s\n" % (key, absent,
160
163
                '\t'.join(flattened_references), value))
161
164
        lines.append('\n')
 
165
        result = StringIO(''.join(lines))
 
166
        if expected_bytes and len(result.getvalue()) != expected_bytes:
 
167
            raise errors.BzrError('Failed index creation. Internal error:'
 
168
                ' mismatched output length and expected length: %d %d' %
 
169
                (len(result.getvalue()), expected_bytes))
162
170
        return StringIO(''.join(lines))
163
171
 
164
172