Beispiel #1
0
    def test_fetch_inconsistent_last_changed_entries(self):
        """If an inventory has odd data we should still get what it references.

        This test tests that we do fetch a file text created in a revision not
        being fetched, but referenced from the revision we are fetching when the
        adjacent revisions to the one being fetched do not reference that text.
        """
        if not self.repository_format.supports_full_versioned_files:
            raise TestNotApplicable('Need full versioned files')
        tree = self.make_branch_and_tree('source')
        revid = tree.commit('old')
        to_repo = self.make_to_repository('to_repo')
        try:
            to_repo.fetch(tree.branch.repository, revid)
        except errors.NoRoundtrippingSupport:
            raise TestNotApplicable('roundtripping not supported')
        # Make a broken revision and fetch it.
        source = tree.branch.repository
        source.lock_write()
        self.addCleanup(source.unlock)
        source.start_write_group()
        try:
            # We need two revisions: OLD and NEW. NEW will claim to need a file
            # 'FOO' changed in 'OLD'. OLD will not have that file at all.
            source.texts.insert_record_stream([
                versionedfile.FulltextContentFactory((b'foo', revid), (), None,
                                                     b'contents')])
            basis = source.revision_tree(revid)
            parent_id = basis.path2id('')
            entry = inventory.make_entry('file', 'foo-path', parent_id, b'foo')
            entry.revision = revid
            entry.text_size = len('contents')
            entry.text_sha1 = osutils.sha_string(b'contents')
            inv_sha1, _ = source.add_inventory_by_delta(revid, [
                (None, 'foo-path', b'foo', entry)], b'new', [revid])
            rev = Revision(timestamp=0,
                           timezone=None,
                           committer="Foo Bar <*****@*****.**>",
                           message="Message",
                           inventory_sha1=inv_sha1,
                           revision_id=b'new',
                           parent_ids=[revid])
            source.add_revision(rev.revision_id, rev)
        except:
            source.abort_write_group()
            raise
        else:
            source.commit_write_group()
        to_repo.fetch(source, b'new')
        to_repo.lock_read()
        self.addCleanup(to_repo.unlock)
        self.assertEqual(b'contents',
                         next(to_repo.texts.get_record_stream([(b'foo', revid)],
                                                              'unordered', True)).get_bytes_as('fulltext'))
Beispiel #2
0
    def record_loom(self, commit_message):
        """Perform a 'commit' to the loom branch.

        :param commit_message: The commit message to use when committing.
        """
        with self.lock_write():
            state = self.get_loom_state()
            parents = state.get_parents()
            old_threads = self.get_threads(state.get_basis_revision_id())
            threads = state.get_threads()
            # check the semantic value, not the serialised value for equality.
            if old_threads == threads:
                raise _mod_commit.PointlessCommit
            builder = self.get_commit_builder(parents)
            loom_ie = _mod_inventory.make_entry('file', 'loom',
                                                _mod_inventory.ROOT_ID,
                                                b'loom_meta_tree')
            writer = loom_io.LoomWriter()
            loom_stream = BytesIO()
            new_threads = [thread[0:2] for thread in threads]
            loom_sha1 = writer.write_threads(new_threads, loom_stream)
            loom_stream.seek(0)
            loom_tree = LoomMetaTree(loom_ie, loom_stream, loom_sha1)
            try:
                basis_revid = parents[0]
            except IndexError:
                basis_revid = breezy.revision.NULL_REVISION
            for unused in builder.record_iter_changes(
                    loom_tree, basis_revid,
                    loom_tree.iter_changes(
                        self.repository.revision_tree(basis_revid))):
                pass
            builder.finish_inventory()
            rev_id = builder.commit(commit_message)
            state.set_parents([rev_id])
            state.set_threads(
                (thread + ([thread[1]], ) for thread in new_threads))
            self._set_last_loom(state)
            return rev_id