~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

  • Committer: John Arbash Meinel
  • Date: 2007-12-18 17:06:42 UTC
  • mto: This revision was merged to the branch mainline in revision 3126.
  • Revision ID: john@arbash-meinel.com-20071218170642-nls9ory76cmh4r6y
Implement get_parent_map for ParentProviders
Add a CachingParentProvider for PackRepository to use.
Add some XFAIL tests for the find_difference algorithm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
996
996
                ', '.join(map(repr, self._indices)))
997
997
 
998
998
    def get_parents(self, revision_ids):
999
 
        """See StackedParentsProvider.get_parents.
 
999
        """See graph._StackedParentsProvider.get_parents.
1000
1000
        
1001
1001
        This implementation thunks the graph.Graph.get_parents api across to
1002
1002
        GraphIndex.
1008
1008
             * (NULL_REVISION,) when the key has no parents.
1009
1009
             * (parent_key, parent_key...) otherwise.
1010
1010
        """
1011
 
        search_keys = set(revision_ids)
1012
 
        search_keys.discard(NULL_REVISION)
1013
 
        found_parents = {NULL_REVISION:[]}
 
1011
        parent_map = self.get_parent_map(revision_ids)
 
1012
        return [parent_map.get(r, None) for r in revision_ids]
 
1013
 
 
1014
    def get_parent_map(self, keys):
 
1015
        """See graph._StackedParentsProvider.get_parent_map"""
 
1016
        search_keys = set(keys)
 
1017
        if NULL_REVISION in search_keys:
 
1018
            search_keys.discard(NULL_REVISION)
 
1019
            found_parents = {NULL_REVISION:[]}
 
1020
        else:
 
1021
            found_parents = {}
1014
1022
        for index, key, value, refs in self.iter_entries(search_keys):
1015
1023
            parents = refs[0]
1016
1024
            if not parents:
1017
1025
                parents = (NULL_REVISION,)
1018
1026
            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
 
1027
        return found_parents
1026
1028
 
1027
1029
    def insert_index(self, pos, index):
1028
1030
        """Insert a new index in the list of indices to query.