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__)
 def test_shared_no_tree_disk_layout(self):
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control, shared=True)
     repo.set_make_working_trees(False)
     # we want:
     # format 'Bazaar-NG Repository format 7'
     # lock ''
     # 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 Repository format 7',
                          t.get('format').read())
     ## self.assertEqualDiff('', t.get('lock').read())
     self.assertEqualDiff('', t.get('shared-storage').read())
     self.assertEqualDiff('', t.get('no-working-trees').read())
     repo.set_make_working_trees(True)
     self.assertFalse(t.has('no-working-trees'))
     self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
     self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
     self.assertEqualDiff('# bzr weave file v5\n'
                          'w\n'
                          'W\n',
                          t.get('inventory.weave').read())
 def test_creates_lockdir(self):
     """Make sure it appears to be controlled by a LockDir existence"""
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control, shared=True)
     t = control.get_repository_transport(None)
     # TODO: Should check there is a 'lock' toplevel directory,
     # regardless of contents
     self.assertFalse(t.has('lock/held/info'))
     repo.lock_write()
     try:
         self.assertTrue(t.has('lock/held/info'))
     finally:
         # unlock so we don't get a warning about failing to do so
         repo.unlock()
 def test_uses_lockdir(self):
     """repo format 7 actually locks on lockdir"""
     base_url = self.get_url()
     control = BzrDirMetaFormat1().initialize(base_url)
     repo = RepositoryFormat7().initialize(control, shared=True)
     t = control.get_repository_transport(None)
     repo.lock_write()
     repo.unlock()
     del repo
     # make sure the same lock is created by opening it
     repo = Repository.open(base_url)
     repo.lock_write()
     self.assertTrue(t.has('lock/held/info'))
     repo.unlock()
     self.assertFalse(t.has('lock/held/info'))
 def test_disk_layout(self):
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control)
     # in case of side effects of locking.
     repo.lock_write()
     repo.unlock()
     # we want:
     # format 'Bazaar-NG Repository format 7'
     # lock ''
     # inventory.weave == empty_weave
     # empty revision-store directory
     # empty weaves directory
     t = control.get_repository_transport(None)
     self.assertEqualDiff('Bazaar-NG Repository format 7',
                          t.get('format').read())
     self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
     self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
     self.assertEqualDiff('# bzr weave file v5\n'
                          'w\n'
                          'W\n',
                          t.get('inventory.weave').read())
     # Creating a file with id Foo:Bar results in a non-escaped file name on
     # disk.
     control.create_branch()
     tree = control.create_workingtree()
     tree.add(['foo'], ['Foo:Bar'], ['file'])
     tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
     try:
         tree.commit('first post', rev_id='first')
     except IllegalPath:
         if sys.platform != 'win32':
             raise
         self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
                           ' in repo format 7')
         return
     self.assertEqualDiff(
         '# bzr weave file v5\n'
         'i\n'
         '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
         'n first\n'
         '\n'
         'w\n'
         '{ 0\n'
         '. content\n'
         '}\n'
         'W\n',
         t.get('weaves/74/Foo%3ABar.weave').read())
    def testSourceFormatChange(self):
        # If a branch that has already been mirrored changes format, then we
        # when we re-mirror the branch, the mirror will acquire the new
        # format.

        # Create and mirror a branch in weave format.
        self._createSourceBranch(RepositoryFormat7(), BzrDirMetaFormat1())
        self.worker.mirror()

        # Change the branch to knit format and mirror again.
        self.get_transport().delete_tree(self._source_branch_path)
        self._createSourceBranch(RepositoryFormatKnit1(), BzrDirMetaFormat1())
        self.worker.mirror()

        # The mirrored branch should now be in knit format.
        self.assertMirrored(
            Branch.open(self.worker.source), Branch.open(self.worker.dest))
 def test_attribute__fetch_uses_deltas(self):
     """Weaves do not reuse deltas."""
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control)
     self.assertEqual(False, repo._format._fetch_uses_deltas)
 def test_attribute__fetch_order(self):
     """Weaves need topological data insertion."""
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control)
     self.assertEqual('topological', repo._format._fetch_order)
 def test_supports_external_lookups(self):
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control)
     self.assertFalse(repo._format.supports_external_lookups)
 def test_attribute__fetch_reconcile(self):
     """Weave repositories need a reconcile after fetch."""
     control = BzrDirMetaFormat1().initialize(self.get_url())
     repo = RepositoryFormat7().initialize(control)
     self.assertEqual(True, repo._format._fetch_reconcile)
 def testMirrorMetaweaveAsMetaweave(self):
     # Create a source branch in metaweave format, and check that the
     # mirror is in metaweave format.
     self._testMirrorWithFormats(RepositoryFormat7(), BzrDirMetaFormat1())
Exemple #12
0
    def convert(self, to_convert, pb):
        """See Converter.convert()."""
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
        from bzrlib.branchfmt.fullhistory import BzrBranchFormat5
        self.bzrdir = to_convert
        self.pb = ui.ui_factory.nested_progress_bar()
        self.count = 0
        self.total = 20  # the steps we know about
        self.garbage_inventories = []
        self.dir_mode = self.bzrdir._get_dir_mode()
        self.file_mode = self.bzrdir._get_file_mode()

        ui.ui_factory.note(
            gettext('starting upgrade from format 6 to metadir'))
        self.bzrdir.transport.put_bytes('branch-format',
                                        "Converting to format 6",
                                        mode=self.file_mode)
        # its faster to move specific files around than to open and use the apis...
        # first off, nuke ancestry.weave, it was never used.
        try:
            self.step(gettext('Removing ancestry.weave'))
            self.bzrdir.transport.delete('ancestry.weave')
        except errors.NoSuchFile:
            pass
        # find out whats there
        self.step(gettext('Finding branch files'))
        last_revision = self.bzrdir.open_branch().last_revision()
        bzrcontents = self.bzrdir.transport.list_dir('.')
        for name in bzrcontents:
            if name.startswith('basis-inventory.'):
                self.garbage_inventories.append(name)
        # create new directories for repository, working tree and branch
        repository_names = [('inventory.weave', True),
                            ('revision-store', True), ('weaves', True)]
        self.step(gettext('Upgrading repository') + '  ')
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
        self.make_lock('repository')
        # we hard code the formats here because we are converting into
        # the meta format. The meta format upgrader can take this to a
        # future format within each component.
        self.put_format('repository', RepositoryFormat7())
        for entry in repository_names:
            self.move_entry('repository', entry)

        self.step(gettext('Upgrading branch') + '      ')
        self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
        self.make_lock('branch')
        self.put_format('branch', BzrBranchFormat5())
        branch_files = [('revision-history', True), ('branch-name', True),
                        ('parent', False)]
        for entry in branch_files:
            self.move_entry('branch', entry)

        checkout_files = [('pending-merges', True), ('inventory', True),
                          ('stat-cache', False)]
        # If a mandatory checkout file is not present, the branch does not have
        # a functional checkout. Do not create a checkout in the converted
        # branch.
        for name, mandatory in checkout_files:
            if mandatory and name not in bzrcontents:
                has_checkout = False
                break
        else:
            has_checkout = True
        if not has_checkout:
            ui.ui_factory.note(gettext('No working tree.'))
            # If some checkout files are there, we may as well get rid of them.
            for name, mandatory in checkout_files:
                if name in bzrcontents:
                    self.bzrdir.transport.delete(name)
        else:
            from bzrlib.workingtree_3 import WorkingTreeFormat3
            self.step(gettext('Upgrading working tree'))
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
            self.make_lock('checkout')
            self.put_format('checkout', WorkingTreeFormat3())
            self.bzrdir.transport.delete_multi(self.garbage_inventories,
                                               self.pb)
            for entry in checkout_files:
                self.move_entry('checkout', entry)
            if last_revision is not None:
                self.bzrdir.transport.put_bytes('checkout/last-revision',
                                                last_revision)
        self.bzrdir.transport.put_bytes(
            'branch-format',
            BzrDirMetaFormat1().get_format_string(),
            mode=self.file_mode)
        self.pb.finished()
        return ControlDir.open(self.bzrdir.user_url)