~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-18 23:41:30 UTC
  • mfrom: (3099.3.7 graph_optimization)
  • Revision ID: pqm@pqm.ubuntu.com-20071218234130-061grgxsaf1g7bao
(jam) Implement ParentProviders.get_parent_map() and deprecate
        get_parents()

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.revision import NULL_REVISION
36
36
from bzrlib.trace import mutter
37
37
""")
38
 
from bzrlib import debug, errors
 
38
from bzrlib import (
 
39
    debug,
 
40
    errors,
 
41
    symbol_versioning,
 
42
    )
39
43
 
40
44
_HEADER_READV = (0, 200)
41
45
_OPTION_KEY_ELEMENTS = "key_elements="
995
999
                self.__class__.__name__,
996
1000
                ', '.join(map(repr, self._indices)))
997
1001
 
 
1002
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
998
1003
    def get_parents(self, revision_ids):
999
 
        """See StackedParentsProvider.get_parents.
 
1004
        """See graph._StackedParentsProvider.get_parents.
1000
1005
        
1001
1006
        This implementation thunks the graph.Graph.get_parents api across to
1002
1007
        GraphIndex.
1008
1013
             * (NULL_REVISION,) when the key has no parents.
1009
1014
             * (parent_key, parent_key...) otherwise.
1010
1015
        """
1011
 
        search_keys = set(revision_ids)
1012
 
        search_keys.discard(NULL_REVISION)
1013
 
        found_parents = {NULL_REVISION:[]}
 
1016
        parent_map = self.get_parent_map(revision_ids)
 
1017
        return [parent_map.get(r, None) for r in revision_ids]
 
1018
 
 
1019
    def get_parent_map(self, keys):
 
1020
        """See graph._StackedParentsProvider.get_parent_map"""
 
1021
        search_keys = set(keys)
 
1022
        if NULL_REVISION in search_keys:
 
1023
            search_keys.discard(NULL_REVISION)
 
1024
            found_parents = {NULL_REVISION:[]}
 
1025
        else:
 
1026
            found_parents = {}
1014
1027
        for index, key, value, refs in self.iter_entries(search_keys):
1015
1028
            parents = refs[0]
1016
1029
            if not parents:
1017
1030
                parents = (NULL_REVISION,)
1018
1031
            found_parents[key] = parents
1019
 
        result = []
1020
 
        for key in revision_ids:
1021
 
            try:
1022
 
                result.append(found_parents[key])
1023
 
            except KeyError:
1024
 
                result.append(None)
1025
 
        return result
 
1032
        return found_parents
1026
1033
 
1027
1034
    def insert_index(self, pos, index):
1028
1035
        """Insert a new index in the list of indices to query.