bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2745.6.7
by Aaron Bentley
Clean-up |
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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2745.6.7
by Aaron Bentley
Clean-up |
16 |
|
17 |
||
18 |
"""Test operations that check the repository for corruption"""
|
|
19 |
||
20 |
||
|
2745.6.1
by Aaron Bentley
Initial checking of knit graphs |
21 |
from bzrlib import ( |
|
2745.6.48
by Andrew Bennetts
Merge find-inconsistent-parents. |
22 |
errors, |
|
2745.6.1
by Aaron Bentley
Initial checking of knit graphs |
23 |
revision as _mod_revision, |
24 |
)
|
|
|
2745.6.48
by Andrew Bennetts
Merge find-inconsistent-parents. |
25 |
from bzrlib.tests import TestNotApplicable |
|
3689.1.1
by John Arbash Meinel
Rename repository_implementations tests into per_repository tests |
26 |
from bzrlib.tests.per_repository import TestCaseWithRepository |
27 |
from bzrlib.tests.per_repository.helpers import ( |
|
|
2819.2.5
by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents. |
28 |
TestCaseWithBrokenRevisionIndex, |
|
2819.2.1
by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents. |
29 |
)
|
30 |
||
31 |
||
|
3036.1.1
by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions. |
32 |
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository): |
33 |
||
34 |
def test_two_files_different_versions_no_inconsistencies_bug_165071(self): |
|
35 |
"""Two files, with different versions can be clean.""" |
|
36 |
tree = self.make_branch_and_tree('.') |
|
37 |
self.build_tree(['foo']) |
|
38 |
tree.smart_add(['.']) |
|
|
4332.3.11
by Robert Collins
Move tree and back callbacks into the repository check core. |
39 |
revid1 = tree.commit('1') |
|
3036.1.1
by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions. |
40 |
self.build_tree(['bar']) |
41 |
tree.smart_add(['.']) |
|
|
4332.3.11
by Robert Collins
Move tree and back callbacks into the repository check core. |
42 |
revid2 = tree.commit('2') |
43 |
check_object = tree.branch.repository.check([revid1, revid2]) |
|
|
4245.1.1
by Ian Clatworthy
minor test clean-ups & _reconcile_pack API |
44 |
check_object.report_results(verbose=True) |
|
3036.1.1
by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions. |
45 |
log = self._get_log(keep_log_file=True) |
|
4332.3.17
by Robert Collins
Check revisions as we cross check the revision index, rather than in a separate pass. |
46 |
self.assertContainsRe(log, "0 unreferenced text versions") |
|
3036.1.1
by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions. |
47 |
|
48 |
||
|
2819.2.5
by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents. |
49 |
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex): |
|
2819.2.1
by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents. |
50 |
|
|
2819.2.2
by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents. |
51 |
def test__find_inconsistent_revision_parents(self): |
52 |
"""_find_inconsistent_revision_parents finds revisions with broken |
|
53 |
parents.
|
|
54 |
"""
|
|
55 |
repo = self.make_repo_with_extra_ghost_index() |
|
|
2819.2.1
by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents. |
56 |
self.assertEqual( |
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
57 |
[('revision-id', ('incorrect-parent',), ())], |
|
2819.2.1
by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents. |
58 |
list(repo._find_inconsistent_revision_parents())) |
59 |
||
|
2819.2.2
by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents. |
60 |
def test__check_for_inconsistent_revision_parents(self): |
61 |
"""_check_for_inconsistent_revision_parents raises BzrCheckError if |
|
62 |
there are any revisions with inconsistent parents.
|
|
63 |
"""
|
|
64 |
repo = self.make_repo_with_extra_ghost_index() |
|
65 |
self.assertRaises( |
|
66 |
errors.BzrCheckError, |
|
67 |
repo._check_for_inconsistent_revision_parents) |
|
68 |
||
69 |
def test__check_for_inconsistent_revision_parents_on_clean_repo(self): |
|
70 |
"""_check_for_inconsistent_revision_parents does nothing if there are |
|
71 |
no broken revisions.
|
|
72 |
"""
|
|
73 |
repo = self.make_repository('empty-repo') |
|
|
2819.2.5
by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents. |
74 |
if not repo.revision_graph_can_have_wrong_parents(): |
75 |
raise TestNotApplicable( |
|
76 |
'%r cannot have corrupt revision index.' % repo) |
|
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
77 |
repo.lock_read() |
78 |
try: |
|
79 |
repo._check_for_inconsistent_revision_parents() # nothing happens |
|
80 |
finally: |
|
81 |
repo.unlock() |
|
|
2819.2.2
by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents. |
82 |
|
|
2819.2.3
by Andrew Bennetts
Add test that repo.check will report on wrong parents in the revision graph. |
83 |
def test_check_reports_bad_ancestor(self): |
84 |
repo = self.make_repo_with_extra_ghost_index() |
|
85 |
# XXX: check requires a non-empty revision IDs list, but it ignores the
|
|
86 |
# contents of it!
|
|
87 |
check_object = repo.check(['ignored']) |
|
88 |
check_object.report_results(verbose=False) |
|
89 |
log = self._get_log(keep_log_file=True) |
|
90 |
self.assertContainsRe( |
|
91 |
log, '1 revisions have incorrect parents in the revision index') |
|
92 |
check_object.report_results(verbose=True) |
|
93 |
log = self._get_log(keep_log_file=True) |
|
94 |
self.assertContainsRe( |
|
95 |
log, |
|
96 |
"revision-id has wrong parents in index: "
|
|
|
2592.3.214
by Robert Collins
Merge bzr.dev. |
97 |
r"\('incorrect-parent',\) should be \(\)") |
|
2819.2.3
by Andrew Bennetts
Add test that repo.check will report on wrong parents in the revision graph. |
98 |
|
|
4332.3.11
by Robert Collins
Move tree and back callbacks into the repository check core. |
99 |
|
100 |
class TestCallbacks(TestCaseWithRepository): |
|
101 |
||
102 |
def test_callback_tree_and_branch(self): |
|
103 |
# use a real tree to get actual refs that will work
|
|
104 |
tree = self.make_branch_and_tree('foo') |
|
105 |
revid = tree.commit('foo') |
|
106 |
tree.lock_read() |
|
107 |
self.addCleanup(tree.unlock) |
|
108 |
needed_refs = {} |
|
109 |
for ref in tree._get_check_refs(): |
|
110 |
needed_refs.setdefault(ref, []).append(tree) |
|
111 |
for ref in tree.branch._get_check_refs(): |
|
112 |
needed_refs.setdefault(ref, []).append(tree.branch) |
|
113 |
self.tree_check = tree._check |
|
114 |
self.branch_check = tree.branch.check |
|
115 |
tree._check = self.tree_callback |
|
116 |
tree.branch.check = self.branch_callback |
|
117 |
self.callbacks = [] |
|
118 |
tree.branch.repository.check([revid], callback_refs=needed_refs) |
|
119 |
self.assertNotEqual([], self.callbacks) |
|
120 |
||
121 |
def tree_callback(self, refs): |
|
122 |
self.callbacks.append(('tree', refs)) |
|
123 |
return self.tree_check(refs) |
|
124 |
||
125 |
def branch_callback(self, refs): |
|
126 |
self.callbacks.append(('branch', refs)) |
|
127 |
return self.branch_check(refs) |