示例#1
0
 def default_test_list():
     """Generate the default list of interrepo permutations to test."""
     from bzrlib.repofmt import knitrepo, pack_repo, weaverepo
     result = []
     # test the default InterRepository between format 6 and the current
     # default format.
     # XXX: robertc 20060220 reinstate this when there are two supported
     # formats which do not have an optimal code path between them.
     #result.append((InterRepository,
     #               RepositoryFormat6(),
     #               RepositoryFormatKnit1()))
     for optimiser_class in InterRepository._optimisers:
         format_to_test = optimiser_class._get_repo_format_to_test()
         if format_to_test is not None:
             result.append(
                 (optimiser_class, format_to_test, format_to_test))
     # if there are specific combinations we want to use, we can add them
     # here.
     result.append((InterModel1and2, weaverepo.RepositoryFormat5(),
                    knitrepo.RepositoryFormatKnit3()))
     result.append((InterModel1and2, knitrepo.RepositoryFormatKnit1(),
                    knitrepo.RepositoryFormatKnit3()))
     result.append((InterKnit1and2, knitrepo.RepositoryFormatKnit1(),
                    knitrepo.RepositoryFormatKnit3()))
     result.append((InterKnitRepo, knitrepo.RepositoryFormatKnit1(),
                    pack_repo.RepositoryFormatKnitPack1()))
     result.append((InterKnitRepo, pack_repo.RepositoryFormatKnitPack1(),
                    knitrepo.RepositoryFormatKnit1()))
     result.append((InterKnitRepo, knitrepo.RepositoryFormatKnit3(),
                    pack_repo.RepositoryFormatKnitPack3()))
     result.append((InterKnitRepo, pack_repo.RepositoryFormatKnitPack3(),
                    knitrepo.RepositoryFormatKnit3()))
     return result
示例#2
0
 def test_is_compatible_and_registered(self):
     # InterWeaveRepo is compatible when either side
     # is a format 5/6/7 branch
     from bzrlib.repofmt import knitrepo
     formats = [
         RepositoryFormat5(),
         RepositoryFormat6(),
         RepositoryFormat7()
     ]
     incompatible_formats = [
         RepositoryFormat4(),
         knitrepo.RepositoryFormatKnit1(),
     ]
     repo_a = self.make_repository('a')
     repo_b = self.make_repository('b')
     is_compatible = InterWeaveRepo.is_compatible
     for source in incompatible_formats:
         # force incompatible left then right
         repo_a._format = source
         repo_b._format = formats[0]
         self.assertFalse(is_compatible(repo_a, repo_b))
         self.assertFalse(is_compatible(repo_b, repo_a))
     for source in formats:
         repo_a._format = source
         for target in formats:
             repo_b._format = target
             self.assertTrue(is_compatible(repo_a, repo_b))
     self.assertEqual(InterWeaveRepo,
                      InterRepository.get(repo_a, repo_b).__class__)
示例#3
0
 def test_convert(self):
     """Ensure the upgrade adds weaves for roots"""
     format = bzrdir.BzrDirMetaFormat1()
     format.repository_format = knitrepo.RepositoryFormatKnit1()
     tree = self.make_branch_and_tree('.', format)
     tree.commit("Dull commit", rev_id="dull")
     revision_tree = tree.branch.repository.revision_tree('dull')
     revision_tree.lock_read()
     try:
         self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
             revision_tree.inventory.root.file_id)
     finally:
         revision_tree.unlock()
     format = bzrdir.BzrDirMetaFormat1()
     format.repository_format = knitrepo.RepositoryFormatKnit3()
     upgrade.Convert('.', format)
     tree = workingtree.WorkingTree.open('.')
     revision_tree = tree.branch.repository.revision_tree('dull')
     revision_tree.lock_read()
     try:
         revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
     finally:
         revision_tree.unlock()
     tree.commit("Another dull commit", rev_id='dull2')
     revision_tree = tree.branch.repository.revision_tree('dull2')
     revision_tree.lock_read()
     self.addCleanup(revision_tree.unlock)
     self.assertEqual('dull', revision_tree.inventory.root.revision)
示例#4
0
 def test_disk_layout(self):
     control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
     repo = knitrepo.RepositoryFormatKnit1().initialize(control)
     # in case of side effects of locking.
     repo.lock_write()
     repo.unlock()
     # we want:
     # format 'Bazaar-NG Knit Repository Format 1'
     # lock: is a directory
     # inventory.weave == empty_weave
     # empty revision-store directory
     # empty weaves directory
     t = control.get_repository_transport(None)
     self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
                          t.get('format').read())
     # XXX: no locks left when unlocked at the moment
     # self.assertEqualDiff('', t.get('lock').read())
     self.assertTrue(S_ISDIR(t.stat('knits').st_mode))
     self.check_knits(t)
     # Check per-file knits.
     branch = control.create_branch()
     tree = control.create_workingtree()
     tree.add(['foo'], ['Nasty-IdC:'], ['file'])
     tree.put_file_bytes_non_atomic('Nasty-IdC:', '')
     tree.commit('1st post', rev_id='foo')
     self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a',
         '\nfoo fulltext 0 81  :')
示例#5
0
 def test_convert_empty(self):
     t = get_transport(self.get_url('.'))
     t.mkdir('repository')
     repo_dir = bzrdir.BzrDirMetaFormat1().initialize('repository')
     repo = weaverepo.RepositoryFormat7().initialize(repo_dir)
     target_format = knitrepo.RepositoryFormatKnit1()
     converter = repository.CopyConverter(target_format)
     pb = bzrlib.ui.ui_factory.nested_progress_bar()
     try:
         converter.convert(repo, pb)
     finally:
         pb.finished()
     repo = repo_dir.open_repository()
     self.assertTrue(isinstance(target_format, repo._format.__class__))
示例#6
0
 def test_shared_disk_layout(self):
     control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
     repo = knitrepo.RepositoryFormatKnit1().initialize(control, shared=True)
     # we want:
     # format 'Bazaar-NG Knit Repository Format 1'
     # lock: is a directory
     # inventory.weave == empty_weave
     # empty revision-store directory
     # empty weaves directory
     # a 'shared-storage' marker file.
     t = control.get_repository_transport(None)
     self.assertEqualDiff('Bazaar-NG Knit Repository Format 1',
                          t.get('format').read())
     # XXX: no locks left when unlocked at the moment
     # self.assertEqualDiff('', t.get('lock').read())
     self.assertEqualDiff('', t.get('shared-storage').read())
     self.assertTrue(S_ISDIR(t.stat('knits').st_mode))
     self.check_knits(t)
示例#7
0
    def test_fetch_root_knit(self):
        """Ensure that knit2.fetch() updates the root knit

        This tests the case where the root has a new revision, but there are no
        corresponding filename, parent, contents or other changes.
        """
        knit1_format = bzrdir.BzrDirMetaFormat1()
        knit1_format.repository_format = knitrepo.RepositoryFormatKnit1()
        knit2_format = bzrdir.BzrDirMetaFormat1()
        knit2_format.repository_format = knitrepo.RepositoryFormatKnit3()
        # we start with a knit1 repository because that causes the
        # root revision to change for each commit, even though the content,
        # parent, name, and other attributes are unchanged.
        tree = self.make_branch_and_tree('tree', knit1_format)
        tree.set_root_id('tree-root')
        tree.commit('rev1', rev_id='rev1')
        tree.commit('rev2', rev_id='rev2')

        # Now we convert it to a knit2 repository so that it has a root knit
        Convert(tree.basedir, knit2_format)
        tree = WorkingTree.open(tree.basedir)
        branch = self.make_branch('branch', format=knit2_format)
        branch.pull(tree.branch, stop_revision='rev1')
        repo = branch.repository
        repo.lock_read()
        try:
            # Make sure fetch retrieved only what we requested
            self.assertEqual({('tree-root', 'rev1'): ()},
                             repo.texts.get_parent_map([('tree-root', 'rev1'),
                                                        ('tree-root', 'rev2')
                                                        ]))
        finally:
            repo.unlock()
        branch.pull(tree.branch)
        # Make sure that the next revision in the root knit was retrieved,
        # even though the text, name, parent_id, etc., were unchanged.
        repo.lock_read()
        try:
            # Make sure fetch retrieved only what we requested
            self.assertEqual(
                {('tree-root', 'rev2'): (('tree-root', 'rev1'), )},
                repo.texts.get_parent_map([('tree-root', 'rev2')]))
        finally:
            repo.unlock()
示例#8
0
    def test_push_only_pushes_history(self):
        # Knit branches should only push the history for the current revision.
        format = bzrdir.BzrDirMetaFormat1()
        format.repository_format = knitrepo.RepositoryFormatKnit1()
        shared_repo = self.make_repository('repo', format=format, shared=True)
        shared_repo.set_make_working_trees(True)

        def make_shared_tree(path):
            shared_repo.bzrdir.root_transport.mkdir(path)
            controldir.ControlDir.create_branch_convenience('repo/' + path)
            return workingtree.WorkingTree.open('repo/' + path)

        tree_a = make_shared_tree('a')
        self.build_tree(['repo/a/file'])
        tree_a.add('file')
        tree_a.commit('commit a-1', rev_id='a-1')
        f = open('repo/a/file', 'ab')
        f.write('more stuff\n')
        f.close()
        tree_a.commit('commit a-2', rev_id='a-2')

        tree_b = make_shared_tree('b')
        self.build_tree(['repo/b/file'])
        tree_b.add('file')
        tree_b.commit('commit b-1', rev_id='b-1')

        self.assertTrue(shared_repo.has_revision('a-1'))
        self.assertTrue(shared_repo.has_revision('a-2'))
        self.assertTrue(shared_repo.has_revision('b-1'))

        # Now that we have a repository with shared files, make sure
        # that things aren't copied out by a 'push'
        self.run_bzr('push ../../push-b', working_dir='repo/b')
        pushed_tree = workingtree.WorkingTree.open('push-b')
        pushed_repo = pushed_tree.branch.repository
        self.assertFalse(pushed_repo.has_revision('a-1'))
        self.assertFalse(pushed_repo.has_revision('a-2'))
        self.assertTrue(pushed_repo.has_revision('b-1'))
示例#9
0
def default_test_list():
    """Generate the default list of interrepo permutations to test."""
    from bzrlib.repofmt import (
        groupcompress_repo,
        knitrepo,
        knitpack_repo,
    )
    result = []

    def add_combo(interrepo_cls,
                  from_format,
                  to_format,
                  extra_setup=None,
                  label=None):
        if label is None:
            label = interrepo_cls.__name__
        result.append((label, from_format, to_format, extra_setup))

    # test the default InterRepository between format 6 and the current
    # default format.
    # XXX: robertc 20060220 reinstate this when there are two supported
    # formats which do not have an optimal code path between them.
    #result.append((InterRepository,
    #               RepositoryFormat6(),
    #               RepositoryFormatKnit1()))
    for optimiser_class in InterRepository._optimisers:
        format_to_test = optimiser_class._get_repo_format_to_test()
        if format_to_test is not None:
            add_combo(optimiser_class, format_to_test, format_to_test)
    # if there are specific combinations we want to use, we can add them
    # here. We want to test rich root upgrading.
    # XXX: although we attach InterRepository class names to these scenarios,
    # there's nothing asserting that these labels correspond to what is
    # actually used.
    def force_known_graph(testcase):
        from bzrlib.fetch import Inter1and2Helper
        testcase.overrideAttr(Inter1and2Helper, 'known_graph_threshold', -1)

    # Gather extra scenarios from the repository implementations,
    # as InterRepositories can be used by Repository implementations
    # they aren't aware of.
    for module_name in format_registry._get_all_modules():
        module = pyutils.get_named_object(module_name)
        try:
            get_extra_interrepo_test_combinations = getattr(
                module, "get_extra_interrepo_test_combinations")
        except AttributeError:
            continue
        for (interrepo_cls, from_format,
             to_format) in (get_extra_interrepo_test_combinations()):
            add_combo(interrepo_cls, from_format, to_format)
    add_combo(InterRepository, knitrepo.RepositoryFormatKnit1(),
              knitrepo.RepositoryFormatKnit3())
    add_combo(knitrepo.InterKnitRepo, knitrepo.RepositoryFormatKnit1(),
              knitpack_repo.RepositoryFormatKnitPack1())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitrepo.RepositoryFormatKnit1())
    add_combo(knitrepo.InterKnitRepo, knitrepo.RepositoryFormatKnit3(),
              knitpack_repo.RepositoryFormatKnitPack3())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack3(),
              knitrepo.RepositoryFormatKnit3())
    add_combo(knitrepo.InterKnitRepo,
              knitpack_repo.RepositoryFormatKnitPack3(),
              knitpack_repo.RepositoryFormatKnitPack4())
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot())
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack1(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot(),
              force_known_graph,
              label='InterDifferingSerializer+get_known_graph_ancestry')
    add_combo(InterDifferingSerializer,
              knitpack_repo.RepositoryFormatKnitPack6RichRoot(),
              groupcompress_repo.RepositoryFormat2a())
    add_combo(InterDifferingSerializer,
              groupcompress_repo.RepositoryFormat2a(),
              knitpack_repo.RepositoryFormatKnitPack6RichRoot())
    return result