~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-24 20:13:57 UTC
  • mto: This revision was merged to the branch mainline in revision 1885.
  • Revision ID: john@arbash-meinel.com-20060724201357-c16e5a568f15a960
Switching to have 'read_records_iter' return in random order.

Show diffs side-by-side

added added

removed removed

Lines of Context:
704
704
        records = [(c, p, s) for c, (m, p, s, n) in position_map.iteritems()]
705
705
        record_map = {}
706
706
        for component_id, content, digest in \
707
 
                self._data.read_records_iter_unsorted(records):
 
707
                self._data.read_records_iter(records):
708
708
            method, position, size, next = position_map[component_id]
709
709
            record_map[component_id] = method, content, digest, next
710
710
                          
806
806
        try:
807
807
            pb.update('Walking content.', count, total)
808
808
            for version_id, data, sha_value in \
809
 
                self._data.read_records_iter_unsorted(version_id_records):
 
809
                self._data.read_records_iter(version_id_records):
810
810
                pb.update('Walking content.', count, total)
811
811
                method = self._index.get_method(version_id)
812
812
                version_idx = self._index.lookup(version_id)
1424
1424
    def read_records_iter(self, records):
1425
1425
        """Read text records from data file and yield result.
1426
1426
 
1427
 
        Each passed record is a tuple of (version_id, pos, len) and
1428
 
        will be read in the given order.  Yields (version_id,
1429
 
        contents, digest).
1430
 
        """
1431
 
        n_records = len(records)
1432
 
        if n_records == 0:
1433
 
            return
1434
 
 
1435
 
        record_requests = {}
1436
 
        for record in records:
1437
 
            y = record_requests.setdefault(record, 0)
1438
 
            y += 1
1439
 
 
1440
 
        # Keep track of where we are in the record list
1441
 
        # Alternatively we could turn this into a new list
1442
 
        # reverse it, and pop off the end, that would let
1443
 
        # us assert that we had gotten through the whole thing
1444
 
        record_stack = iter(records)
1445
 
        next_record = record_stack.next()
1446
 
 
1447
 
        yield_count = 0
1448
 
        record_map = {}
1449
 
        for version_id, content, digest in \
1450
 
                self.read_records_iter_unsorted(records):
1451
 
            record_map[version_id] = (content, digest)
1452
 
 
1453
 
            while next_record[0] in record_map:
1454
 
                next_content, next_digest = record_map[next_record[0]]
1455
 
                record_requests[next_record] -= 1
1456
 
                if record_requests[next_record] == 0:
1457
 
                    del record_map.pop[next_record]
1458
 
                yield_count += 1
1459
 
                yield next_record[0], next_content, next_digest
1460
 
                next_record = record_stack.next()
1461
 
 
1462
 
        # When we get this far, the record_stack should be empty
1463
 
        assert yield_count == n_records
1464
 
        assert record_map == {}, 'We still have records queued up'
1465
 
 
1466
 
    def read_records_iter_unsorted(self, records):
1467
 
        """Read text records from data file and yield result.
1468
 
 
1469
1427
        The result will be returned in whatever is the fastest to read.
1470
1428
        Not by the order requested. Also, multiple requests for the same
1471
1429
        record will only yield 1 response.
1513
1471
        """Read records into a dictionary."""
1514
1472
        components = {}
1515
1473
        for record_id, content, digest in \
1516
 
                self.read_records_iter_unsorted(records):
 
1474
                self.read_records_iter(records):
1517
1475
            components[record_id] = (content, digest)
1518
1476
        return components
1519
1477