/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/index.py

  • Committer: Robert Collins
  • Date: 2007-07-13 10:29:22 UTC
  • mto: (2592.5.3 pack-repository)
  • mto: This revision was merged to the branch mainline in revision 2624.
  • Revision ID: robertc@robertcollins.net-20070713102922-v3ge2itsa8460o6i
Test missing end lines with non-empty indices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
188
188
            defined order for the result iteration - it will be in the most
189
189
            efficient order for the index.
190
190
        """
191
 
        return []
 
191
        stream = self._transport.get(self._name)
 
192
        self._read_prefix(stream)
 
193
        line_count = 0
 
194
        keys_by_offset = {}
 
195
        trailers = 0
 
196
        pos = stream.tell()
 
197
        for line in stream.readlines():
 
198
            if line == '\n':
 
199
                trailers += 1
 
200
                continue
 
201
            key, absent, references, value = line[:-1].split('\0')
 
202
            keys_by_offset[pos] = (key, absent, references, value)
 
203
        for key, absent, references, value in keys_by_offset.values():
 
204
            yield (key, (), value)
 
205
        if trailers != 1:
 
206
            # there must be one line - the empty trailer line.
 
207
            raise errors.BadIndexData(self)
 
208
 
 
209
    def _read_prefix(self, stream):
 
210
        signature = stream.read(len(self._signature()))
 
211
        if not signature == self._signature():
 
212
            raise errors.BadIndexFormatSignature(self._name, GraphIndex)
 
213
        options_line = stream.readline()
 
214
        if not options_line.startswith(_OPTION_NODE_REFS):
 
215
            raise errors.BadIndexOptions(self)
 
216
        try:
 
217
            self.node_ref_lists = int(options_line[len(_OPTION_NODE_REFS):-1])
 
218
        except ValueError:
 
219
            raise errors.BadIndexOptions(self)
192
220
 
193
221
    def iter_entries(self, keys):
194
222
        """Iterate over keys within the index.
210
238
 
211
239
    def validate(self):
212
240
        """Validate that everything in the index can be accessed."""
213
 
        stream = self._transport.get(self._name)
214
 
        signature = stream.read(len(self._signature()))
215
 
        if not signature == self._signature():
216
 
            raise errors.BadIndexFormatSignature(self._name, GraphIndex)
217
 
        options_line = stream.readline()
218
 
        if not options_line.startswith(_OPTION_NODE_REFS):
219
 
            raise errors.BadIndexOptions(self)
220
 
        try:
221
 
            node_ref_lists = int(options_line[len(_OPTION_NODE_REFS):-1])
222
 
        except ValueError:
223
 
            raise errors.BadIndexOptions(self)
224
 
        line_count = 0
225
 
        for line in stream.readlines():
226
 
            # validate the line
227
 
            line_count += 1
228
 
        if line_count < 1:
229
 
            # there must be one line - the empty trailer line.
230
 
            raise errors.BadIndexData(self)
 
241
        # iter_all validates completely at the moment, so just do that.
 
242
        for node in self.iter_all_entries():
 
243
            pass