~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/serializer/v4.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-03 01:20:07 UTC
  • mfrom: (2916.2.18 faster-bundles)
  • Revision ID: pqm@pqm.ubuntu.com-20071203012007-1tfytfzp7piacl7q
Use iter_records_from_file rather than ContainerReader to make bundle
        reading a bit faster. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
            source_file = iterablefile.IterableFile(self.iter_decode(fileobj))
161
161
        else:
162
162
            source_file = StringIO(bz2.decompress(fileobj.read()))
163
 
        self._container = pack.ContainerReader(source_file)
 
163
        self._container_file = source_file
164
164
 
165
165
    @staticmethod
166
166
    def iter_decode(fileobj):
167
167
        """Iterate through decoded fragments of the file"""
168
168
        decompressor = bz2.BZ2Decompressor()
169
169
        for line in fileobj:
170
 
            yield decompressor.decompress(line)
 
170
            try:
 
171
                yield decompressor.decompress(line)
 
172
            except EOFError:
 
173
                return
171
174
 
172
175
    @staticmethod
173
176
    def decode_name(name):
199
202
        :return: a generator of (bytes, metadata, content_kind, revision_id,
200
203
            file_id)
201
204
        """
202
 
        iterator = self._container.iter_records()
203
 
        for names, meta_bytes in iterator:
 
205
        iterator = pack.iter_records_from_file(self._container_file)
 
206
        for names, bytes in iterator:
204
207
            if len(names) != 1:
205
208
                raise errors.BadBundle('Record has %d names instead of 1'
206
209
                                       % len(names))
207
 
            metadata = bencode.bdecode(meta_bytes(None))
 
210
            metadata = bencode.bdecode(bytes)
208
211
            if metadata['storage_kind'] == 'header':
209
212
                bytes = None
210
213
            else:
211
214
                _unused, bytes = iterator.next()
212
 
                bytes = bytes(None)
213
215
            yield (bytes, metadata) + self.decode_name(names[0][0])
214
216
 
215
217