~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-23 20:04:42 UTC
  • mto: (3735.2.161 brisbane-core)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090323200442-10qwt4ws636wwjwl
Cleanup, in preparation for merging to brisbane-core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
494
494
                return self._manager._wire_bytes()
495
495
            else:
496
496
                return ''
497
 
            self._manager = None # safe?
498
497
        if storage_kind in ('fulltext', 'chunked'):
499
498
            if self._bytes is None:
500
 
                # Grab the raw bytes for this entry, and break the ref-cycle
 
499
                # Grab and cache the raw bytes for this entry
 
500
                # and break the ref-cycle with _manager since we don't need it
 
501
                # anymore
501
502
                self._manager._prepare_for_extract()
502
503
                block = self._manager._block
503
504
                self._bytes = block.extract(self.key, self._start, self._end)
507
508
            else:
508
509
                return [self._bytes]
509
510
        raise errors.UnavailableRepresentation(self.key, storage_kind,
510
 
            self.storage_kind)
 
511
                                               self.storage_kind)
511
512
 
512
513
 
513
514
class _LazyGroupContentManager(object):
534
535
        """Get a record for all keys added so far."""
535
536
        for factory in self._factories:
536
537
            yield factory
 
538
            # Break the ref-cycle
537
539
            factory._bytes = None
538
540
            factory._manager = None
539
541
        # TODO: Consider setting self._factories = None after the above loop,
1286
1288
        for key in missing:
1287
1289
            yield AbsentContentFactory(key)
1288
1290
        manager = None
1289
 
        last_block = None
1290
 
        last_memo = None
 
1291
        last_read_memo = None
1291
1292
        # TODO: This works fairly well at batching up existing groups into a
1292
1293
        #       streamable format, and possibly allowing for taking one big
1293
1294
        #       group and splitting it when it isn't fully utilized.
1302
1303
                for key in keys:
1303
1304
                    if key in self._unadded_refs:
1304
1305
                        if manager is not None:
1305
 
                            # Yield everything buffered so far
1306
1306
                            for factory in manager.get_record_stream():
1307
1307
                                yield factory
1308
 
                                # Disable this record, breaks the refcycle, and
1309
 
                                # saves memory. But this means clients really
1310
 
                                # *cannot* hang on to objects.
1311
 
                                factory._bytes = None
1312
 
                                factory._manager = None
1313
 
                            manager = None
 
1308
                            last_read_memo = manager = None
1314
1309
                        bytes, sha1 = self._compressor.extract(key)
1315
1310
                        parents = self._unadded_refs[key]
1316
1311
                        yield FulltextContentFactory(key, parents, sha1, bytes)
1317
1312
                    else:
1318
1313
                        index_memo, _, parents, (method, _) = locations[key]
1319
1314
                        read_memo = index_memo[0:3]
1320
 
                        if last_memo == read_memo:
1321
 
                            block = last_block
1322
 
                        else:
 
1315
                        if last_read_memo != read_memo:
 
1316
                            # We are starting a new block. If we have a
 
1317
                            # manager, we have found everything that fits for
 
1318
                            # now, so yield records
 
1319
                            if manager is not None:
 
1320
                                for factory in manager.get_record_stream():
 
1321
                                    yield factory
 
1322
                            # Now start a new manager
1323
1323
                            block = self._get_block(index_memo)
1324
 
                            last_block = block
1325
 
                            last_memo = read_memo
 
1324
                            manager = _LazyGroupContentManager(block)
 
1325
                            last_read_memo = read_memo
1326
1326
                        start, end = index_memo[3:5]
1327
 
                        if manager is None:
1328
 
                            manager = _LazyGroupContentManager(block)
1329
 
                        elif manager._block is not block:
1330
 
                            # Flush and create a new manager
1331
 
                            for factory in manager.get_record_stream():
1332
 
                                yield factory
1333
 
                            manager = _LazyGroupContentManager(block)
1334
1327
                        manager.add_factory(key, parents, start, end)
1335
1328
            else:
1336
1329
                if manager is not None:
1337
 
                    # Yield everything buffered so far
1338
1330
                    for factory in manager.get_record_stream():
1339
1331
                        yield factory
1340
 
                    manager = None
 
1332
                    last_read_memo = manager = None
1341
1333
                for record in source.get_record_stream(keys, ordering,
1342
1334
                                                       include_delta_closure):
1343
1335
                    yield record
1344
1336
        if manager is not None:
1345
 
            # Yield everything buffered so far
1346
1337
            for factory in manager.get_record_stream():
1347
1338
                yield factory
1348
 
            manager = None
1349
1339
 
1350
1340
    def get_sha1s(self, keys):
1351
1341
        """See VersionedFiles.get_sha1s()."""