~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 02:23:31 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220022331-hbm91o1ps9gjrlns
Add testr magic for bzr selftest --list

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib import (
30
30
    xml5,
31
31
    graph as _mod_graph,
 
32
    ui,
32
33
    )
33
34
""")
34
35
from bzrlib import (
38
39
    lockable_files,
39
40
    lockdir,
40
41
    osutils,
41
 
    revision as _mod_revision,
42
42
    trace,
43
43
    urlutils,
44
44
    versionedfile,
48
48
from bzrlib.decorators import needs_read_lock, needs_write_lock
49
49
from bzrlib.repository import (
50
50
    CommitBuilder,
 
51
    InterRepository,
 
52
    InterSameDataRepository,
51
53
    MetaDirVersionedFileRepository,
52
54
    MetaDirRepositoryFormat,
53
55
    Repository,
738
740
        paths = list(relpaths)
739
741
        return set([self._mapper.unmap(path) for path in paths])
740
742
 
 
743
 
 
744
class InterWeaveRepo(InterSameDataRepository):
 
745
    """Optimised code paths between Weave based repositories.
 
746
 
 
747
    This should be in bzrlib/repofmt/weaverepo.py but we have not yet
 
748
    implemented lazy inter-object optimisation.
 
749
    """
 
750
 
 
751
    @classmethod
 
752
    def _get_repo_format_to_test(self):
 
753
        return RepositoryFormat7()
 
754
 
 
755
    @staticmethod
 
756
    def is_compatible(source, target):
 
757
        """Be compatible with known Weave formats.
 
758
 
 
759
        We don't test for the stores being of specific types because that
 
760
        could lead to confusing results, and there is no need to be
 
761
        overly general.
 
762
        """
 
763
        try:
 
764
            return (isinstance(source._format, (RepositoryFormat5,
 
765
                                                RepositoryFormat6,
 
766
                                                RepositoryFormat7)) and
 
767
                    isinstance(target._format, (RepositoryFormat5,
 
768
                                                RepositoryFormat6,
 
769
                                                RepositoryFormat7)))
 
770
        except AttributeError:
 
771
            return False
 
772
 
 
773
    @needs_write_lock
 
774
    def copy_content(self, revision_id=None):
 
775
        """See InterRepository.copy_content()."""
 
776
        # weave specific optimised path:
 
777
        try:
 
778
            self.target.set_make_working_trees(self.source.make_working_trees())
 
779
        except (errors.RepositoryUpgradeRequired, NotImplemented):
 
780
            pass
 
781
        # FIXME do not peek!
 
782
        if self.source._transport.listable():
 
783
            pb = ui.ui_factory.nested_progress_bar()
 
784
            try:
 
785
                self.target.texts.insert_record_stream(
 
786
                    self.source.texts.get_record_stream(
 
787
                        self.source.texts.keys(), 'topological', False))
 
788
                pb.update('Copying inventory', 0, 1)
 
789
                self.target.inventories.insert_record_stream(
 
790
                    self.source.inventories.get_record_stream(
 
791
                        self.source.inventories.keys(), 'topological', False))
 
792
                self.target.signatures.insert_record_stream(
 
793
                    self.source.signatures.get_record_stream(
 
794
                        self.source.signatures.keys(),
 
795
                        'unordered', True))
 
796
                self.target.revisions.insert_record_stream(
 
797
                    self.source.revisions.get_record_stream(
 
798
                        self.source.revisions.keys(),
 
799
                        'topological', True))
 
800
            finally:
 
801
                pb.finished()
 
802
        else:
 
803
            self.target.fetch(self.source, revision_id=revision_id)
 
804
 
 
805
    @needs_read_lock
 
806
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
807
        """See InterRepository.missing_revision_ids()."""
 
808
        # we want all revisions to satisfy revision_id in source.
 
809
        # but we don't want to stat every file here and there.
 
810
        # we want then, all revisions other needs to satisfy revision_id
 
811
        # checked, but not those that we have locally.
 
812
        # so the first thing is to get a subset of the revisions to
 
813
        # satisfy revision_id in source, and then eliminate those that
 
814
        # we do already have.
 
815
        # this is slow on high latency connection to self, but as this
 
816
        # disk format scales terribly for push anyway due to rewriting
 
817
        # inventory.weave, this is considered acceptable.
 
818
        # - RBC 20060209
 
819
        if revision_id is not None:
 
820
            source_ids = self.source.get_ancestry(revision_id)
 
821
            if source_ids[0] is not None:
 
822
                raise AssertionError()
 
823
            source_ids.pop(0)
 
824
        else:
 
825
            source_ids = self.source._all_possible_ids()
 
826
        source_ids_set = set(source_ids)
 
827
        # source_ids is the worst possible case we may need to pull.
 
828
        # now we want to filter source_ids against what we actually
 
829
        # have in target, but don't try to check for existence where we know
 
830
        # we do not have a revision as that would be pointless.
 
831
        target_ids = set(self.target._all_possible_ids())
 
832
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
833
        actually_present_revisions = set(
 
834
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
835
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
836
        if revision_id is not None:
 
837
            # we used get_ancestry to determine source_ids then we are assured all
 
838
            # revisions referenced are present as they are installed in topological order.
 
839
            # and the tip revision was validated by get_ancestry.
 
840
            result_set = required_revisions
 
841
        else:
 
842
            # if we just grabbed the possibly available ids, then
 
843
            # we only have an estimate of whats available and need to validate
 
844
            # that against the revision records.
 
845
            result_set = set(
 
846
                self.source._eliminate_revisions_not_present(required_revisions))
 
847
        return self.source.revision_ids_to_search_result(result_set)
 
848
 
 
849
 
741
850
_legacy_formats = [RepositoryFormat4(),
742
851
                   RepositoryFormat5(),
743
852
                   RepositoryFormat6()]
 
853
 
 
854
 
 
855
InterRepository.register_optimiser(InterWeaveRepo)