def test_straightline_ancestry(self):
     """Test ancestry file when just committing."""
     builder = BranchBuilder(self.get_transport())
     rev_id_one = builder.build_commit()
     rev_id_two = builder.build_commit()
     branch = builder.get_branch()
     self.assertThat([rev_id_one, rev_id_two],
         MatchesAncestry(branch.repository, rev_id_two))
     self.assertThat([rev_id_one],
         MatchesAncestry(branch.repository, rev_id_one))
Exemple #2
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, 'ghost')
     reported_wrong = False
     try:
         if m.match(['the_ghost', '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, 'ghost')
Exemple #3
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, 'ghost')
     reported_wrong = False
     try:
         if m.match(['the_ghost', '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, 'ghost')
 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('ghost')
     self.assertThat(['ghost', 'the_ghost'], MatchesAncestry(repo, 'ghost'))
 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, 'ghost')
     if m.match(['the_ghost', 'ghost']) is None:
         # the repo handles ghosts without corruption, so reconcile has
         # nothing to do
         return
     self.assertThat(['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('ghost')
     repo.get_inventory('the_ghost')
     self.assertThat(['the_ghost', 'ghost'], MatchesAncestry(repo, 'ghost'))
     self.assertThat(['the_ghost'], MatchesAncestry(repo, 'the_ghost'))
    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 = bzrlib.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, 'ghost', [])
        add_commit(has_ghost, 'references', ['ghost'])
        add_commit(missing_ghost, 'references', ['ghost'])
        add_commit(has_ghost, 'tip', ['references'])
        missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True)
        # missing ghost now has tip and ghost.
        rev = missing_ghost.get_revision('tip')
        inv = missing_ghost.get_inventory('tip')
        rev = missing_ghost.get_revision('ghost')
        inv = missing_ghost.get_inventory('ghost')
        # rev must not be corrupt now
        self.assertThat(['ghost', 'references', 'tip'],
            MatchesAncestry(missing_ghost, 'tip'))
Exemple #7
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, 'ghost')
     if m.match(['the_ghost', 'ghost']) is None:
         # the repo handles ghosts without corruption, so reconcile has
         # nothing to do
         return
     self.assertThat(['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('ghost')
     repo.get_inventory('the_ghost')
     self.assertThat(['the_ghost', 'ghost'],
         MatchesAncestry(repo, 'ghost'))
     self.assertThat(['the_ghost'],
         MatchesAncestry(repo, 'the_ghost'))
 def test_committed_ancestry(self):
     """Test commit appends revisions to ancestry."""
     wt = self.make_branch_and_tree('.')
     b = wt.branch
     rev_ids = []
     for i in range(4):
         with file('hello', 'w') as f:
             f.write((str(i) * 4) + '\n')
         if i == 0:
             wt.add(['hello'], ['hello-id'])
         rev_id = 'test@rev-%d' % (i + 1)
         rev_ids.append(rev_id)
         wt.commit(message='rev %d' % (i + 1), rev_id=rev_id)
     for i in range(4):
         self.assertThat(rev_ids[:i + 1],
                         MatchesAncestry(b.repository, rev_ids[i]))
Exemple #9
0
 def test_recorded_ancestry(self):
     """Test that commit records all ancestors"""
     br1, br2 = make_branches(self)
     d = [
         ('a@u-0-0', ['a@u-0-0']),
         ('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
         ('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
         ('b@u-0-3', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3']),
         ('b@u-0-4',
          ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4']),
         ('a@u-0-3', [
             'a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
             'a@u-0-3'
         ]),
         ('a@u-0-4', [
             'a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
             'a@u-0-3', 'a@u-0-4'
         ]),
         ('b@u-0-5', [
             'a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
             'b@u-0-5'
         ]),
         ('a@u-0-5', [
             'a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
             'b@u-0-3', 'b@u-0-4', 'b@u-0-5', 'a@u-0-5'
         ]),
         ('b@u-0-6', [
             'a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-4', 'b@u-0-3',
             'b@u-0-4', 'b@u-0-5', 'b@u-0-6'
         ]),
     ]
     br1_only = ('a@u-0-3', 'a@u-0-4', 'a@u-0-5')
     br2_only = ('b@u-0-6', )
     for branch in br1, br2:
         for rev_id, anc in d:
             if rev_id in br1_only and not branch is br1:
                 continue
             if rev_id in br2_only and not branch is br2:
                 continue
             self.assertThat(anc, MatchesAncestry(branch.repository,
                                                  rev_id))