~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

Merge fix for bug #388269 into trunk, resolve conflicts and add release notes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    def __repr__(self):
59
59
        return 'DictParentsProvider(%r)' % self.ancestry
60
60
 
 
61
    # Note: DictParentsProvider does not implement get_cached_parent_map
 
62
    #       Arguably, the data is clearly cached in memory. However, this class
 
63
    #       is mostly used for testing, and it keeps the tests clean to not
 
64
    #       change it.
 
65
 
61
66
    def get_parent_map(self, keys):
62
67
        """See StackedParentsProvider.get_parent_map"""
63
68
        ancestry = self.ancestry
66
71
 
67
72
class StackedParentsProvider(object):
68
73
    """A parents provider which stacks (or unions) multiple providers.
69
 
    
 
74
 
70
75
    The providers are queries in the order of the provided parent_providers.
71
76
    """
72
 
    
 
77
 
73
78
    def __init__(self, parent_providers):
74
79
        self._parent_providers = parent_providers
75
80
 
91
96
        """
92
97
        found = {}
93
98
        remaining = set(keys)
 
99
        # This adds getattr() overhead to each get_parent_map call. However,
 
100
        # this is StackedParentsProvider, which means we're dealing with I/O
 
101
        # (either local indexes, or remote RPCs), so CPU overhead should be
 
102
        # minimal.
 
103
        for parents_provider in self._parent_providers:
 
104
            get_cached = getattr(parents_provider, 'get_cached_parent_map',
 
105
                                 None)
 
106
            if get_cached is None:
 
107
                continue
 
108
            new_found = get_cached(remaining)
 
109
            found.update(new_found)
 
110
            remaining.difference_update(new_found)
 
111
            if not remaining:
 
112
                break
 
113
        if not remaining:
 
114
            return found
94
115
        for parents_provider in self._parent_providers:
95
116
            new_found = parents_provider.get_parent_map(remaining)
96
117
            found.update(new_found)
150
171
            return None
151
172
        return dict(self._cache)
152
173
 
 
174
    def get_cached_parent_map(self, keys):
 
175
        """Return items from the cache.
 
176
 
 
177
        This returns the same info as get_parent_map, but explicitly does not
 
178
        invoke the supplied ParentsProvider to search for uncached values.
 
179
        """
 
180
        cache = self._cache
 
181
        if cache is None:
 
182
            return {}
 
183
        return dict([(key, cache[key]) for key in keys if key in cache])
 
184
 
153
185
    def get_parent_map(self, keys):
154
186
        """See StackedParentsProvider.get_parent_map."""
155
187
        cache = self._cache