56
53
# maps (file-id, version) -> sha1; used by InventoryFile._check
57
54
self.checked_texts = {}
58
55
self.checked_weaves = {}
59
self.unreferenced_versions = set()
60
self.inconsistent_parents = []
63
58
self.repository.lock_read()
64
59
self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
66
self.progress.update('retrieving inventory', 0, 2)
61
self.progress.update('retrieving inventory', 0, 0)
67
62
# do not put in init, as it should be done with progess,
68
63
# and inside the lock.
69
64
self.inventory_weave = self.repository.get_inventory_weave()
70
self.progress.update('checking revision graph', 1)
71
self.check_revision_graph()
72
65
self.plan_revisions()
74
68
while revno < len(self.planned_revisions):
75
69
rev_id = self.planned_revisions[revno]
76
70
self.progress.update('checking revision', revno,
77
71
len(self.planned_revisions))
79
73
self.check_one_rev(rev_id)
80
# check_weaves is done after the revision scan so that
81
# revision index is known to be valid.
84
75
self.progress.finished()
85
76
self.repository.unlock()
87
def check_revision_graph(self):
88
if not self.repository.revision_graph_can_have_wrong_parents():
89
# This check is not necessary.
90
self.revs_with_bad_parents_in_index = None
92
bad_revisions = self.repository._find_inconsistent_revision_parents()
93
self.revs_with_bad_parents_in_index = list(bad_revisions)
95
78
def plan_revisions(self):
96
79
repository = self.repository
97
self.planned_revisions = repository.all_revision_ids()
80
self.planned_revisions = set(repository.all_revision_ids())
98
81
self.progress.clear()
99
82
inventoried = set(self.inventory_weave.versions())
100
awol = set(self.planned_revisions) - inventoried
83
awol = self.planned_revisions - inventoried
102
85
raise BzrCheckError('Stored revisions missing from inventory'
103
86
'{%s}' % ','.join([f for f in awol]))
87
self.planned_revisions = list(self.planned_revisions)
105
89
def report_results(self, verbose):
106
90
note('checked repository %s format %s',
107
91
self.repository.bzrdir.root_transport,
108
92
self.repository._format)
109
93
note('%6d revisions', self.checked_rev_cnt)
110
note('%6d file-ids', len(self.checked_weaves))
111
94
note('%6d unique file texts', self.checked_text_cnt)
112
95
note('%6d repeated file texts', self.repeated_text_cnt)
113
note('%6d unreferenced text versions',
114
len(self.unreferenced_versions))
96
note('%6d weaves', len(self.checked_weaves))
115
97
if self.missing_inventory_sha_cnt:
116
98
note('%6d revisions are missing inventory_sha1',
117
99
self.missing_inventory_sha_cnt)
131
113
note(' %s should be in the ancestry for:', link)
132
114
for linker in linkers:
133
115
note(' * %s', linker)
135
for file_id, revision_id in self.unreferenced_versions:
136
log_error('unreferenced version: {%s} in %s', revision_id,
138
if len(self.inconsistent_parents):
139
note('%6d inconsistent parents', len(self.inconsistent_parents))
141
for info in self.inconsistent_parents:
142
revision_id, file_id, found_parents, correct_parents = info
143
note(' * %s version %s has parents %r '
145
% (file_id, revision_id, found_parents,
147
if self.revs_with_bad_parents_in_index:
148
note('%6d revisions have incorrect parents in the revision index',
149
len(self.revs_with_bad_parents_in_index))
151
for item in self.revs_with_bad_parents_in_index:
152
revision_id, index_parents, actual_parents = item
154
' %s has wrong parents in index: '
156
revision_id, index_parents, actual_parents)
158
117
def check_one_rev(self, rev_id):
159
118
"""Check one revision.
198
157
if self.repository.weave_store.listable():
199
158
weave_ids = list(self.repository.weave_store)
200
n_weaves = len(weave_ids) + 1
201
self.progress.update('checking versionedfile', 0, n_weaves)
159
n_weaves = len(weave_ids)
160
self.progress.update('checking weave', 0, n_weaves)
202
161
self.inventory_weave.check(progress_bar=self.progress)
203
files_in_revisions = {}
204
revisions_of_files = {}
205
weave_checker = self.repository._get_versioned_file_checker()
206
162
for i, weave_id in enumerate(weave_ids):
207
self.progress.update('checking versionedfile', i, n_weaves)
163
self.progress.update('checking weave', i, n_weaves)
208
164
w = self.repository.weave_store.get_weave(weave_id,
209
165
self.repository.get_transaction())
210
166
# No progress here, because it looks ugly.
212
result = weave_checker.check_file_version_parents(w, weave_id)
213
bad_parents, unused_versions = result
214
bad_parents = bad_parents.items()
215
for revision_id, (weave_parents, correct_parents) in bad_parents:
216
self.inconsistent_parents.append(
217
(revision_id, weave_id, weave_parents, correct_parents))
218
for revision_id in unused_versions:
219
self.unreferenced_versions.add((weave_id, revision_id))
220
168
self.checked_weaves[weave_id] = True
222
170
def _check_revision_tree(self, rev_id):