2819.2.5
by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""Helper classes for repository implementation tests."""
|
|
18 |
||
19 |
||
20 |
from bzrlib import ( |
|
21 |
inventory, |
|
22 |
revision as _mod_revision, |
|
23 |
)
|
|
24 |
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit |
|
25 |
from bzrlib.tests.repository_implementations import TestCaseWithRepository |
|
26 |
from bzrlib.tests import TestNotApplicable |
|
27 |
||
28 |
||
29 |
class TestCaseWithBrokenRevisionIndex(TestCaseWithRepository): |
|
30 |
||
31 |
def make_repo_with_extra_ghost_index(self): |
|
32 |
"""Make a corrupt repository.
|
|
33 |
|
|
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.
|
|
37 |
||
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.
|
|
41 |
"""
|
|
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) |
|
49 |
||
50 |
repo = self.make_repository('broken') |
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
51 |
repo.lock_write() |
52 |
repo.start_write_group() |
|
53 |
try: |
|
54 |
inv = inventory.Inventory(revision_id='revision-id') |
|
55 |
inv.root.revision = 'revision-id' |
|
56 |
repo.add_inventory('revision-id', inv, []) |
|
57 |
revision = _mod_revision.Revision('revision-id', |
|
58 |
committer='jrandom@example.com', timestamp=0, |
|
59 |
inventory_sha1='', timezone=0, message='message', parent_ids=[]) |
|
60 |
repo.add_revision('revision-id',revision, inv) |
|
61 |
except: |
|
62 |
repo.abort_write_group() |
|
63 |
repo.unlock() |
|
64 |
raise
|
|
2592.3.215
by Robert Collins
Review feedback. |
65 |
else: |
2592.3.214
by Robert Collins
Merge bzr.dev. |
66 |
repo.commit_write_group() |
67 |
repo.unlock() |
|
2819.2.5
by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents. |
68 |
|
69 |
# Change the knit index's record of the parents for 'revision-id' to
|
|
70 |
# claim it has a parent, 'incorrect-parent', that doesn't exist in this
|
|
71 |
# knit at all.
|
|
72 |
repo.lock_write() |
|
73 |
self.addCleanup(repo.unlock) |
|
74 |
rev_knit = repo._get_revision_vf() |
|
75 |
index_cache = rev_knit._index._cache |
|
76 |
cached_index_entry = list(index_cache['revision-id']) |
|
77 |
cached_index_entry[4] = ['incorrect-parent'] |
|
78 |
index_cache['revision-id'] = tuple(cached_index_entry) |
|
79 |
return repo |
|
80 |