bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
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  | 
||
| 
2951.1.3
by Robert Collins
 Partial support for native reconcile with packs.  | 
19  | 
from cStringIO import StringIO  | 
| 
2819.2.5
by Andrew Bennetts
 Make reconcile abort gracefully if the revision index has bad parents.  | 
20  | 
|
21  | 
from bzrlib import (  | 
|
22  | 
inventory,  | 
|
| 
2951.1.3
by Robert Collins
 Partial support for native reconcile with packs.  | 
23  | 
osutils,  | 
| 
2819.2.5
by Andrew Bennetts
 Make reconcile abort gracefully if the revision index has bad parents.  | 
24  | 
revision as _mod_revision,  | 
25  | 
    )
 | 
|
26  | 
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit  | 
|
27  | 
from bzrlib.tests.repository_implementations import TestCaseWithRepository  | 
|
28  | 
from bzrlib.tests import TestNotApplicable  | 
|
29  | 
||
30  | 
||
31  | 
class TestCaseWithBrokenRevisionIndex(TestCaseWithRepository):  | 
|
32  | 
||
33  | 
def make_repo_with_extra_ghost_index(self):  | 
|
34  | 
"""Make a corrupt repository.  | 
|
35  | 
        
 | 
|
36  | 
        It will contain one revision, 'revision-id'.  The knit index will claim
 | 
|
37  | 
        that it has one parent, 'incorrect-parent', but the revision text will
 | 
|
38  | 
        claim it has no parents.
 | 
|
39  | 
||
40  | 
        Note: only the *cache* of the knit index is corrupted.  Thus the
 | 
|
41  | 
        corruption will only last while the repository is locked.  For this
 | 
|
42  | 
        reason, the returned repo is locked.
 | 
|
43  | 
        """
 | 
|
44  | 
if not isinstance(self.repository_format, RepositoryFormatKnit):  | 
|
45  | 
            # XXX: Broken revision graphs can happen to weaves too, but they're
 | 
|
46  | 
            # pretty deprecated.  Ideally these tests should apply to any repo
 | 
|
47  | 
            # where repo.revision_graph_can_have_wrong_parents() is True, but
 | 
|
48  | 
            # at the moment we only know how to corrupt knit repos.
 | 
|
49  | 
raise TestNotApplicable(  | 
|
50  | 
"%s isn't a knit format" % self.repository_format)  | 
|
51  | 
||
52  | 
repo = self.make_repository('broken')  | 
|
| 
2592.3.214
by Robert Collins
 Merge bzr.dev.  | 
53  | 
repo.lock_write()  | 
54  | 
repo.start_write_group()  | 
|
55  | 
try:  | 
|
56  | 
inv = inventory.Inventory(revision_id='revision-id')  | 
|
57  | 
inv.root.revision = 'revision-id'  | 
|
| 
2951.1.3
by Robert Collins
 Partial support for native reconcile with packs.  | 
58  | 
inv_sha1 = repo.add_inventory('revision-id', inv, [])  | 
| 
2951.1.5
by Robert Collins
 Some work towards including the correct changes for TREE_ROOT in check parameterised tests.  | 
59  | 
if repo.supports_rich_root():  | 
60  | 
root_id = inv.root.file_id  | 
|
61  | 
vf = repo.weave_store.get_weave_or_empty(root_id,  | 
|
62  | 
repo.get_transaction())  | 
|
63  | 
vf.add_lines('revision-id', [], [])  | 
|
| 
2592.3.214
by Robert Collins
 Merge bzr.dev.  | 
64  | 
revision = _mod_revision.Revision('revision-id',  | 
65  | 
committer='jrandom@example.com', timestamp=0,  | 
|
| 
2951.1.3
by Robert Collins
 Partial support for native reconcile with packs.  | 
66  | 
inventory_sha1=inv_sha1, timezone=0, message='message',  | 
67  | 
parent_ids=[])  | 
|
68  | 
            # Manually add the revision text using the RevisionStore API, with
 | 
|
69  | 
            # bad parents.
 | 
|
70  | 
rev_tmp = StringIO()  | 
|
71  | 
repo._revision_store._serializer.write_revision(revision, rev_tmp)  | 
|
72  | 
rev_tmp.seek(0)  | 
|
73  | 
repo._revision_store.get_revision_file(repo.get_transaction()  | 
|
74  | 
).add_lines_with_ghosts(revision.revision_id,  | 
|
75  | 
['incorrect-parent'],  | 
|
76  | 
osutils.split_lines(rev_tmp.read()))  | 
|
| 
2592.3.214
by Robert Collins
 Merge bzr.dev.  | 
77  | 
except:  | 
78  | 
repo.abort_write_group()  | 
|
79  | 
repo.unlock()  | 
|
80  | 
            raise
 | 
|
| 
2592.3.215
by Robert Collins
 Review feedback.  | 
81  | 
else:  | 
| 
2592.3.214
by Robert Collins
 Merge bzr.dev.  | 
82  | 
repo.commit_write_group()  | 
83  | 
repo.unlock()  | 
|
| 
2819.2.5
by Andrew Bennetts
 Make reconcile abort gracefully if the revision index has bad parents.  | 
84  | 
|
85  | 
repo.lock_write()  | 
|
86  | 
self.addCleanup(repo.unlock)  | 
|
87  | 
return repo  | 
|
88  |