1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Helper classes for repository implementation tests."""
22
revision as _mod_revision,
24
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit
25
from bzrlib.tests.repository_implementations import TestCaseWithRepository
26
from bzrlib.tests import TestNotApplicable
29
class TestCaseWithBrokenRevisionIndex(TestCaseWithRepository):
31
def make_repo_with_extra_ghost_index(self):
32
"""Make a corrupt repository.
34
It will contain one revision, 'revision-id'. The knit index will claim
35
that it has one parent, 'incorrect-parent', but the revision text will
36
claim it has no parents.
38
Note: only the *cache* of the knit index is corrupted. Thus the
39
corruption will only last while the repository is locked. For this
40
reason, the returned repo is locked.
42
if not isinstance(self.repository_format, RepositoryFormatKnit):
43
# XXX: Broken revision graphs can happen to weaves too, but they're
44
# pretty deprecated. Ideally these tests should apply to any repo
45
# where repo.revision_graph_can_have_wrong_parents() is True, but
46
# at the moment we only know how to corrupt knit repos.
47
raise TestNotApplicable(
48
"%s isn't a knit format" % self.repository_format)
50
repo = self.make_repository('broken')
51
inv = inventory.Inventory(revision_id='revision-id')
52
inv.root.revision = 'revision-id'
53
repo.add_inventory('revision-id', inv, [])
54
revision = _mod_revision.Revision('revision-id',
55
committer='jrandom@example.com', timestamp=0,
56
inventory_sha1='', timezone=0, message='message', parent_ids=[])
57
repo.add_revision('revision-id',revision, inv)
59
# Change the knit index's record of the parents for 'revision-id' to
60
# claim it has a parent, 'incorrect-parent', that doesn't exist in this
63
self.addCleanup(repo.unlock)
64
rev_knit = repo._get_revision_vf()
65
index_cache = rev_knit._index._cache
66
cached_index_entry = list(index_cache['revision-id'])
67
cached_index_entry[4] = ['incorrect-parent']
68
index_cache['revision-id'] = tuple(cached_index_entry)