~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2011-05-04 02:34:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5839.
  • Revision ID: andrew.bennetts@canonical.com-20110504023405-2o1o97b5d759db9b
Be a little more clever about constructing a parents provider for stacked repositories, so that get_parent_map with local-stacked-on-remote doesn't use HPSS VFS calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2623
2623
                result[revision_id] = (_mod_revision.NULL_REVISION,)
2624
2624
        return result
2625
2625
 
 
2626
    def _get_parent_map_no_fallbacks(self, revision_ids):
 
2627
        """Same as Repository.get_parent_map except doesn't query fallbacks."""
 
2628
        # revisions index works in keys; this just works in revisions
 
2629
        # therefore wrap and unwrap
 
2630
        query_keys = []
 
2631
        result = {}
 
2632
        for revision_id in revision_ids:
 
2633
            if revision_id == _mod_revision.NULL_REVISION:
 
2634
                result[revision_id] = ()
 
2635
            elif revision_id is None:
 
2636
                raise ValueError('get_parent_map(None) is not valid')
 
2637
            else:
 
2638
                query_keys.append((revision_id ,))
 
2639
        vf = self.revisions.without_fallbacks()
 
2640
        for ((revision_id,), parent_keys) in \
 
2641
                vf.get_parent_map(query_keys).iteritems():
 
2642
            if parent_keys:
 
2643
                result[revision_id] = tuple([parent_revid
 
2644
                    for (parent_revid,) in parent_keys])
 
2645
            else:
 
2646
                result[revision_id] = (_mod_revision.NULL_REVISION,)
 
2647
        return result
 
2648
 
2626
2649
    def _make_parents_provider(self):
2627
 
        return self
 
2650
        if not self._format.supports_external_lookups:
 
2651
            return self
 
2652
        return graph.StackedParentsProvider(_FallbacksList(self))
 
2653
 
 
2654
    def _make_parents_provider_with_no_fallbacks(self):
 
2655
        return graph.CallableToParentsProviderAdapter(
 
2656
            self._get_parent_map_no_fallbacks)
2628
2657
 
2629
2658
    @needs_read_lock
2630
2659
    def get_known_graph_ancestry(self, revision_ids):
4517
4546
    except StopIteration:
4518
4547
        # No more history
4519
4548
        return
 
4549
 
 
4550
 
 
4551
class _FallbacksList(object):
 
4552
    """An iterable yielding a repo followed by its fallbacks.
 
4553
 
 
4554
    Each iterator made from this will reflect the current list of
 
4555
    fallbacks at the time the iterator is made.
 
4556
    
 
4557
    i.e. if a _make_parents_provider implementation uses
 
4558
    StackedParentsProvider(_FallbacksList(self)), then it is safe to do::
 
4559
 
 
4560
      pp = repo._make_parents_provider()
 
4561
      pp.add_fallback_repository(other_repo)
 
4562
      result = pp.get_parent_map(...)
 
4563
      # The result will include revs from other_repo
 
4564
    """
 
4565
 
 
4566
    def __init__(self, repo):
 
4567
        self.repo = repo
 
4568
 
 
4569
    def __iter__(self):
 
4570
        repo_pp = self.repo._make_parents_provider_with_no_fallbacks()
 
4571
        return iter([repo_pp] + self.repo._fallback_repositories)
 
4572