示例#1
0
 def test_corrupt_revision_access_asserts_if_reported_wrong(self):
     repo_url = self.get_url('inventory_with_unnecessary_ghost')
     repo = _mod_repository.Repository.open(repo_url)
     m = MatchesAncestry(repo, b'ghost')
     reported_wrong = False
     try:
         if m.match([b'the_ghost', b'ghost']) is not None:
             reported_wrong = True
     except errors.CorruptRepository:
         # caught the bad data:
         return
     if not reported_wrong:
         return
     self.assertRaises(errors.CorruptRepository, repo.get_revision,
                       b'ghost')
示例#2
0
    def test_fetch_all_fixes_up_ghost(self):
        # we want two repositories at this point:
        # one with a revision that is a ghost in the other
        # repository.
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
        # 'references' is present in both repositories, and 'tip' is present
        # just in has_ghost.
        # has_ghost       missing_ghost
        # ------------------------------
        # 'ghost'             -
        # 'references'    'references'
        # 'tip'               -
        # In this test we fetch 'tip' which should not fetch 'ghost'
        has_ghost = self.make_repository('has_ghost')
        missing_ghost = self.make_repository('missing_ghost')
        if [True, True] != [
                repo._format.supports_ghosts
                for repo in (has_ghost, missing_ghost)
        ]:
            raise TestNotApplicable("Need ghost support.")

        def add_commit(repo, revision_id, parent_ids):
            repo.lock_write()
            repo.start_write_group()
            inv = Inventory(revision_id=revision_id)
            inv.root.revision = revision_id
            root_id = inv.root.file_id
            sha1 = repo.add_inventory(revision_id, inv, parent_ids)
            repo.texts.add_lines((root_id, revision_id), [], [])
            rev = breezy.revision.Revision(
                timestamp=0,
                timezone=None,
                committer="Foo Bar <*****@*****.**>",
                message="Message",
                inventory_sha1=sha1,
                revision_id=revision_id)
            rev.parent_ids = parent_ids
            repo.add_revision(revision_id, rev)
            repo.commit_write_group()
            repo.unlock()

        add_commit(has_ghost, b'ghost', [])
        add_commit(has_ghost, b'references', [b'ghost'])
        add_commit(missing_ghost, b'references', [b'ghost'])
        add_commit(has_ghost, b'tip', [b'references'])
        missing_ghost.fetch(has_ghost, b'tip', find_ghosts=True)
        # missing ghost now has tip and ghost.
        rev = missing_ghost.get_revision(b'tip')
        inv = missing_ghost.get_inventory(b'tip')
        rev = missing_ghost.get_revision(b'ghost')
        inv = missing_ghost.get_inventory(b'ghost')
        # rev must not be corrupt now
        self.assertThat([b'ghost', b'references', b'tip'],
                        MatchesAncestry(missing_ghost, b'tip'))
示例#3
0
 def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
     d = BzrDir.open(self.get_url('inventory_one_ghost'))
     reconciler = d.open_repository().reconcile(thorough=True)
     # no inconsistent parents should have been found:
     # the lack of a parent for ghost is normal
     self.assertEqual(0, reconciler.inconsistent_parents)
     # and one garbage inventories
     self.assertEqual(0, reconciler.garbage_inventories)
     # now the current inventory should still have 'ghost'
     repo = d.open_repository()
     repo.get_inventory(b'ghost')
     self.assertThat([b'ghost', b'the_ghost'],
                     MatchesAncestry(repo, b'ghost'))
示例#4
0
 def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
     d = BzrDir.open(self.get_url('inventory_ghost_present'))
     repo = d.open_repository()
     m = MatchesAncestry(repo, b'ghost')
     if m.match([b'the_ghost', b'ghost']) is None:
         # the repo handles ghosts without corruption, so reconcile has
         # nothing to do
         return
     self.assertThat([b'ghost'], m)
     reconciler = repo.reconcile()
     # this is a data corrupting error, so a normal reconcile should fix it.
     # one inconsistent parents should have been found : the
     # available but not reference parent for ghost.
     self.assertEqual(1, reconciler.inconsistent_parents)
     # and no garbage inventories
     self.assertEqual(0, reconciler.garbage_inventories)
     # now the current inventory should still have 'ghost'
     repo = d.open_repository()
     repo.get_inventory(b'ghost')
     repo.get_inventory(b'the_ghost')
     self.assertThat([b'the_ghost', b'ghost'],
                     MatchesAncestry(repo, b'ghost'))
     self.assertThat([b'the_ghost'], MatchesAncestry(repo, b'the_ghost'))
示例#5
0
 def test_recorded_ancestry(self):
     """Test that commit records all ancestors"""
     br1, br2 = make_branches(self)
     d = [
         (b'a@u-0-0', [b'a@u-0-0']),
         (b'a@u-0-1', [b'a@u-0-0', b'a@u-0-1']),
         (b'a@u-0-2', [b'a@u-0-0', b'a@u-0-1', b'a@u-0-2']),
         (b'b@u-0-3', [b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'b@u-0-3']),
         (b'b@u-0-4',
          [b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'b@u-0-3', b'b@u-0-4']),
         (b'a@u-0-3', [
             b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'b@u-0-3', b'b@u-0-4',
             b'a@u-0-3'
         ]),
         (b'a@u-0-4', [
             b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'b@u-0-3', b'b@u-0-4',
             b'a@u-0-3', b'a@u-0-4'
         ]),
         (b'b@u-0-5', [
             b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'b@u-0-3', b'b@u-0-4',
             b'b@u-0-5'
         ]),
         (b'a@u-0-5', [
             b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'a@u-0-3', b'a@u-0-4',
             b'b@u-0-3', b'b@u-0-4', b'b@u-0-5', b'a@u-0-5'
         ]),
         (b'b@u-0-6', [
             b'a@u-0-0', b'a@u-0-1', b'a@u-0-2', b'a@u-0-4', b'b@u-0-3',
             b'b@u-0-4', b'b@u-0-5', b'b@u-0-6'
         ]),
     ]
     br1_only = (b'a@u-0-3', b'a@u-0-4', b'a@u-0-5')
     br2_only = (b'b@u-0-6', )
     for branch in br1, br2:
         for rev_id, anc in d:
             if rev_id in br1_only and branch is not br1:
                 continue
             if rev_id in br2_only and branch is not br2:
                 continue
             self.assertThat(anc, MatchesAncestry(branch.repository,
                                                  rev_id))