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

  • Committer: Aaron Bentley
  • Date: 2008-11-22 16:24:28 UTC
  • mto: This revision was merged to the branch mainline in revision 3892.
  • Revision ID: aaron@aaronbentley.com-20081122162428-o9vik1937s3p8fmy
Move CachingExtraParentsProvider to Graph

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
                'Does not support nested trees', target_format)
288
288
 
289
289
 
290
 
class _UnstackedParentsProvider(object):
291
 
    """ParentsProvider for RemoteRepository that ignores stacking."""
292
 
 
293
 
    def __init__(self, get_parent_map):
294
 
        self._get_parent_map = get_parent_map
295
 
        self._parents_map = None
296
 
        if 'hpss' in debug.debug_flags:
297
 
            self._requested_parents = None
298
 
 
299
 
    def enable_cache(self):
300
 
        """Enable cache."""
301
 
        self._parents_map = {}
302
 
        if 'hpss' in debug.debug_flags:
303
 
            self._requested_parents = set()
304
 
 
305
 
    def disable_cache(self):
306
 
        """Disable cache."""
307
 
        self._parents_map = None
308
 
        if 'hpss' in debug.debug_flags:
309
 
            self._requested_parents = None
310
 
 
311
 
    def get_cached_map(self):
312
 
        """Return any cached get_parent_map values."""
313
 
        return self._parents_map
314
 
 
315
 
    def get_parent_map(self, keys):
316
 
        """See RemoteRepository.get_parent_map."""
317
 
        # Hack to build up the caching logic.
318
 
        ancestry = self._parents_map
319
 
        if ancestry is None:
320
 
            # Repository is not locked, so there's no cache.
321
 
            missing_revisions = set(keys)
322
 
            ancestry = {}
323
 
        else:
324
 
            missing_revisions = set(key for key in keys if key not in ancestry)
325
 
        if missing_revisions:
326
 
            parent_map = self._get_parent_map(missing_revisions)
327
 
            if 'hpss' in debug.debug_flags:
328
 
                mutter('retransmitted revisions: %d of %d',
329
 
                        len(set(ancestry).intersection(parent_map)),
330
 
                        len(parent_map))
331
 
            ancestry.update(parent_map)
332
 
        present_keys = [k for k in keys if k in ancestry]
333
 
        if 'hpss' in debug.debug_flags:
334
 
            if self._requested_parents is not None and len(ancestry) != 0:
335
 
                self._requested_parents.update(present_keys)
336
 
                mutter('Current RemoteRepository graph hit rate: %d%%',
337
 
                    100.0 * len(self._requested_parents) / len(ancestry))
338
 
        return dict((k, ancestry[k]) for k in present_keys)
339
 
 
340
 
 
341
290
class RemoteRepository(_RpcHelper):
342
291
    """Repository accessed over rpc.
343
292
 
370
319
        self._lock_token = None
371
320
        self._lock_count = 0
372
321
        self._leave_lock = False
373
 
        self._unstacked_provider = _UnstackedParentsProvider(
374
 
            self._get_parent_map_rpc)
 
322
        debug_cache = ('hpss' in debug.debug_flags)
 
323
        self._unstacked_provider = graph.CachingExtraParentsProvider(
 
324
            self._get_parent_map_rpc, debug_cache)
375
325
        # For tests:
376
326
        # These depend on the actual remote format, so force them off for
377
327
        # maximum compatibility. XXX: In future these should depend on the