~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

Add source index to the index iteration API to allow mapping back to the origin of retrieved data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
314
314
            self._buffer_all()
315
315
        if self.node_ref_lists:
316
316
            for key, (value, node_ref_lists) in self._nodes.iteritems():
317
 
                yield key, value, node_ref_lists
 
317
                yield self, key, value, node_ref_lists
318
318
        else:
319
319
            for key, value in self._nodes.iteritems():
320
 
                yield key, value
 
320
                yield self, key, value
321
321
 
322
322
    def _read_prefix(self, stream):
323
323
        signature = stream.read(len(self._signature()))
355
355
        if self.node_ref_lists:
356
356
            for key in keys:
357
357
                value, node_refs = self._nodes[key]
358
 
                yield key, value, node_refs
 
358
                yield self, key, value, node_refs
359
359
        else:
360
360
            for key in keys:
361
 
                yield key, self._nodes[key]
 
361
                yield self, key, self._nodes[key]
362
362
 
363
363
    def iter_entries_prefix(self, keys):
364
364
        """Iterate over keys within the index using prefix matching.
392
392
                    raise errors.BadIndexKey(key)
393
393
                if self.node_ref_lists:
394
394
                    value, node_refs = self._nodes[key]
395
 
                    yield key, value, node_refs
 
395
                    yield self, key, value, node_refs
396
396
                else:
397
 
                    yield key, self._nodes[key]
 
397
                    yield self, key, self._nodes[key]
398
398
            return
399
399
        for key in keys:
400
400
            # sanity check
427
427
                        for value in key_dict.itervalues():
428
428
                            # each value is the key:value:node refs tuple
429
429
                            # ready to yield.
430
 
                            yield value
 
430
                            yield (self, ) + value
431
431
            else:
432
432
                # the last thing looked up was a terminal element
433
 
                yield key_dict
 
433
                yield (self, ) + key_dict
434
434
 
435
435
    def _signature(self):
436
436
        """The file signature for this index type."""
484
484
        seen_keys = set()
485
485
        for index in self._indices:
486
486
            for node in index.iter_all_entries():
487
 
                if node[0] not in seen_keys:
 
487
                if node[1] not in seen_keys:
488
488
                    yield node
489
 
                    seen_keys.add(node[0])
 
489
                    seen_keys.add(node[1])
490
490
 
491
491
    def iter_entries(self, keys):
492
492
        """Iterate over keys within the index.
504
504
            if not keys:
505
505
                return
506
506
            for node in index.iter_entries(keys):
507
 
                keys.remove(node[0])
 
507
                keys.remove(node[1])
508
508
                yield node
509
509
 
510
510
    def iter_entries_prefix(self, keys):
533
533
        seen_keys = set()
534
534
        for index in self._indices:
535
535
            for node in index.iter_entries_prefix(keys):
536
 
                if node[0] in seen_keys:
 
536
                if node[1] in seen_keys:
537
537
                    continue
538
 
                seen_keys.add(node[0])
 
538
                seen_keys.add(node[1])
539
539
                yield node
540
540
 
541
541
    def validate(self):
574
574
        if self.reference_lists:
575
575
            for key, (absent, references, value) in self._nodes.iteritems():
576
576
                if not absent:
577
 
                    yield key, value, references
 
577
                    yield self, key, value, references
578
578
        else:
579
579
            for key, (absent, references, value) in self._nodes.iteritems():
580
580
                if not absent:
581
 
                    yield key, value
 
581
                    yield self, key, value
582
582
 
583
583
    def iter_entries(self, keys):
584
584
        """Iterate over keys within the index.
593
593
            for key in keys.intersection(self._nodes):
594
594
                node = self._nodes[key]
595
595
                if not node[0]:
596
 
                    yield key, node[2], node[1]
 
596
                    yield self, key, node[2], node[1]
597
597
        else:
598
598
            for key in keys.intersection(self._nodes):
599
599
                node = self._nodes[key]
600
600
                if not node[0]:
601
 
                    yield key, node[2]
 
601
                    yield self, key, node[2]
602
602
 
603
603
    def iter_entries_prefix(self, keys):
604
604
        """Iterate over keys within the index using prefix matching.
633
633
                if node[0]:
634
634
                    continue 
635
635
                if self.reference_lists:
636
 
                    yield key, node[2], node[1]
 
636
                    yield self, key, node[2], node[1]
637
637
                else:
638
 
                    yield key, node[2]
 
638
                    yield self ,key, node[2]
639
639
            return
640
640
        for key in keys:
641
641
            # sanity check
666
666
                    else:
667
667
                        # yield keys
668
668
                        for value in key_dict.itervalues():
669
 
                            yield value
 
669
                            yield (self, ) + value
670
670
            else:
671
 
                yield key_dict
 
671
                yield (self, ) + key_dict
672
672
 
673
673
    def validate(self):
674
674
        """In memory index's have no known corruption at the moment."""
732
732
        """Strip prefix data from nodes and return it."""
733
733
        for node in an_iter:
734
734
            # cross checks
735
 
            if node[0][:self.prefix_len] != self.prefix_key:
 
735
            if node[1][:self.prefix_len] != self.prefix_key:
736
736
                raise errors.BadIndexData(self)
737
 
            for ref_list in node[2]:
 
737
            for ref_list in node[3]:
738
738
                for ref_node in ref_list:
739
739
                    if ref_node[:self.prefix_len] != self.prefix_key:
740
740
                        raise errors.BadIndexData(self)
741
 
            yield node[0][self.prefix_len:], node[1], (
 
741
            yield node[0], node[1][self.prefix_len:], node[2], (
742
742
                tuple(tuple(ref_node[self.prefix_len:] for ref_node in ref_list)
743
 
                for ref_list in node[2]))
 
743
                for ref_list in node[3]))
744
744
 
745
745
    def iter_all_entries(self):
746
746
        """Iterate over all keys within the index