~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 03:43:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5839.
  • Revision ID: andrew.bennetts@canonical.com-20110504034303-urnokits2dcybaqt
Add test for calling add_fallback_repository after _make_parents_provider, and make it work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2649
2649
    def _make_parents_provider(self):
2650
2650
        if not self._format.supports_external_lookups:
2651
2651
            return self
2652
 
        return graph.StackedParentsProvider(_FallbacksList(self))
 
2652
        return graph.StackedParentsProvider(_LazyListJoin(
 
2653
            [self._make_parents_provider_unstacked()],
 
2654
            self._fallback_repositories))
2653
2655
 
2654
 
    def _make_parents_provider_with_no_fallbacks(self):
 
2656
    def _make_parents_provider_unstacked(self):
2655
2657
        return graph.CallableToParentsProviderAdapter(
2656
2658
            self._get_parent_map_no_fallbacks)
2657
2659
 
4548
4550
        return
4549
4551
 
4550
4552
 
4551
 
class _FallbacksList(object):
4552
 
    """An iterable yielding a repo followed by its fallbacks.
 
4553
class _LazyListJoin(object):
 
4554
    """An iterable yielding the contents of many lists as one list.
4553
4555
 
4554
 
    Each iterator made from this will reflect the current list of
4555
 
    fallbacks at the time the iterator is made.
 
4556
    Each iterator made from this will reflect the current contents of the lists
 
4557
    at the time the iterator is made.
4556
4558
    
4557
 
    i.e. if a _make_parents_provider implementation uses
4558
 
    StackedParentsProvider(_FallbacksList(self)), then it is safe to do::
 
4559
    This is used by Repository's _make_parents_provider implementation so that
 
4560
    it is safe to do::
4559
4561
 
4560
 
      pp = repo._make_parents_provider()
4561
 
      pp.add_fallback_repository(other_repo)
 
4562
      pp = repo._make_parents_provider()      # uses a list of fallback repos
 
4563
      pp.add_fallback_repository(other_repo)  # appends to that list
4562
4564
      result = pp.get_parent_map(...)
4563
4565
      # The result will include revs from other_repo
4564
4566
    """
4565
4567
 
4566
 
    def __init__(self, repo):
4567
 
        self.repo = repo
 
4568
    def __init__(self, *list_parts):
 
4569
        self.list_parts = list_parts
4568
4570
 
4569
4571
    def __iter__(self):
4570
 
        repo_pp = self.repo._make_parents_provider_with_no_fallbacks()
4571
 
        return iter([repo_pp] + self.repo._fallback_repositories)
 
4572
        full_list = []
 
4573
        for list_part in self.list_parts:
 
4574
            full_list.extend(list_part)
 
4575
        return iter(full_list)
4572
4576