53
56
# maps (file-id, version) -> sha1; used by InventoryFile._check
54
57
self.checked_texts = {}
55
58
self.checked_weaves = {}
59
self.unreferenced_versions = set()
60
self.inconsistent_parents = []
58
63
self.repository.lock_read()
59
64
self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
61
self.progress.update('retrieving inventory', 0, 0)
66
self.progress.update('retrieving inventory', 0, 2)
62
67
# do not put in init, as it should be done with progess,
63
68
# and inside the lock.
64
69
self.inventory_weave = self.repository.get_inventory_weave()
70
self.progress.update('checking revision graph', 1)
71
self.check_revision_graph()
65
72
self.plan_revisions()
68
74
while revno < len(self.planned_revisions):
69
75
rev_id = self.planned_revisions[revno]
70
76
self.progress.update('checking revision', revno,
71
77
len(self.planned_revisions))
73
79
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.
75
84
self.progress.finished()
76
85
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)
78
95
def plan_revisions(self):
79
96
repository = self.repository
80
self.planned_revisions = set(repository.all_revision_ids())
97
self.planned_revisions = repository.all_revision_ids()
81
98
self.progress.clear()
82
99
inventoried = set(self.inventory_weave.versions())
83
awol = self.planned_revisions - inventoried
100
awol = set(self.planned_revisions) - inventoried
85
102
raise BzrCheckError('Stored revisions missing from inventory'
86
103
'{%s}' % ','.join([f for f in awol]))
87
self.planned_revisions = list(self.planned_revisions)
89
105
def report_results(self, verbose):
90
106
note('checked repository %s format %s',
91
107
self.repository.bzrdir.root_transport,
92
108
self.repository._format)
93
109
note('%6d revisions', self.checked_rev_cnt)
110
note('%6d file-ids', len(self.checked_weaves))
94
111
note('%6d unique file texts', self.checked_text_cnt)
95
112
note('%6d repeated file texts', self.repeated_text_cnt)
96
note('%6d weaves', len(self.checked_weaves))
113
note('%6d unreferenced text versions',
114
len(self.unreferenced_versions))
97
115
if self.missing_inventory_sha_cnt:
98
116
note('%6d revisions are missing inventory_sha1',
99
117
self.missing_inventory_sha_cnt)
113
131
note(' %s should be in the ancestry for:', link)
114
132
for linker in linkers:
115
133
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)
117
158
def check_one_rev(self, rev_id):
118
159
"""Check one revision.
157
198
if self.repository.weave_store.listable():
158
199
weave_ids = list(self.repository.weave_store)
159
200
n_weaves = len(weave_ids) + 1
160
self.progress.update('checking weave', 0, n_weaves)
201
self.progress.update('checking versionedfile', 0, n_weaves)
161
202
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()
162
206
for i, weave_id in enumerate(weave_ids):
163
self.progress.update('checking weave', i, n_weaves)
207
self.progress.update('checking versionedfile', i, n_weaves)
164
208
w = self.repository.weave_store.get_weave(weave_id,
165
209
self.repository.get_transaction())
166
210
# 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))
168
220
self.checked_weaves[weave_id] = True
170
222
def _check_revision_tree(self, rev_id):