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

  • Committer: Robert J. Tanner
  • Date: 2009-04-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2692
2692
    """A KnitVersionedFiles index layered on GraphIndex."""
2693
2693
 
2694
2694
    def __init__(self, graph_index, is_locked, deltas=False, parents=True,
2695
 
        add_callback=None):
 
2695
        add_callback=None, track_external_parent_refs=False):
2696
2696
        """Construct a KnitGraphIndex on a graph_index.
2697
2697
 
2698
2698
        :param graph_index: An implementation of bzrlib.index.GraphIndex.
2706
2706
            [(node, value, node_refs), ...]
2707
2707
        :param is_locked: A callback, returns True if the index is locked and
2708
2708
            thus usable.
 
2709
        :param track_external_parent_refs: If True, record all external parent
 
2710
            references parents from added records.  These can be retrieved
 
2711
            later by calling get_missing_parents().
2709
2712
        """
2710
2713
        self._add_callback = add_callback
2711
2714
        self._graph_index = graph_index
2719
2722
        self.has_graph = parents
2720
2723
        self._is_locked = is_locked
2721
2724
        self._missing_compression_parents = set()
 
2725
        if track_external_parent_refs:
 
2726
            self._external_parent_refs = set()
 
2727
        else:
 
2728
            self._external_parent_refs = None
2722
2729
 
2723
2730
    def __repr__(self):
2724
2731
        return "%s(%r)" % (self.__class__.__name__, self._graph_index)
2748
2755
 
2749
2756
        keys = {}
2750
2757
        compression_parents = set()
 
2758
        parent_refs = self._external_parent_refs
2751
2759
        for (key, options, access_memo, parents) in records:
2752
2760
            if self._parents:
2753
2761
                parents = tuple(parents)
 
2762
                if parent_refs is not None:
 
2763
                    parent_refs.update(parents)
 
2764
                    parent_refs.discard(key)
2754
2765
            index, pos, size = access_memo
2755
2766
            if 'no-eol' in options:
2756
2767
                value = 'N'
2818
2829
            new_missing = graph_index.external_references(ref_list_num=1)
2819
2830
            new_missing.difference_update(self.get_parent_map(new_missing))
2820
2831
            self._missing_compression_parents.update(new_missing)
 
2832
        if self._external_parent_refs is not None:
 
2833
            # Add parent refs from graph_index (and discard parent refs that
 
2834
            # the graph_index has).
 
2835
            for node in graph_index.iter_all_entries():
 
2836
                self._external_parent_refs.update(node[3][0])
 
2837
                self._external_parent_refs.discard(node[1])
2821
2838
 
2822
2839
    def get_missing_compression_parents(self):
2823
2840
        """Return the keys of missing compression parents.
2827
2844
        """
2828
2845
        return frozenset(self._missing_compression_parents)
2829
2846
 
 
2847
    def get_missing_parents(self):
 
2848
        """Return the keys of missing parents."""
 
2849
        # We may have false positives, so filter those out.
 
2850
        self._external_parent_refs.difference_update(
 
2851
            self.get_parent_map(self._external_parent_refs))
 
2852
        return frozenset(self._external_parent_refs)
 
2853
 
2830
2854
    def _check_read(self):
2831
2855
        """raise if reads are not permitted."""
2832
2856
        if not self._is_locked():