193
206
def check_weaves(self):
194
207
"""Check all the weaves we can get our hands on.
198
if self.repository.weave_store.listable():
199
weave_ids = list(self.repository.weave_store)
200
n_weaves = len(weave_ids) + 1
201
self.progress.update('checking versionedfile', 0, n_weaves)
210
self.progress.update('checking inventory', 0, 2)
202
211
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
for i, weave_id in enumerate(weave_ids):
207
self.progress.update('checking versionedfile', i, n_weaves)
208
w = self.repository.weave_store.get_weave(weave_id,
209
self.repository.get_transaction())
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))
220
self.checked_weaves[weave_id] = True
212
self.progress.update('checking text storage', 1, 2)
213
self.repository.texts.check(progress_bar=self.progress)
214
weave_checker = self.repository._get_versioned_file_checker(
215
text_key_references=self.text_key_references)
216
result = weave_checker.check_file_version_parents(
217
self.repository.texts, progress_bar=self.progress)
218
self.checked_weaves = weave_checker.file_ids
219
bad_parents, unused_versions = result
220
bad_parents = bad_parents.items()
221
for text_key, (stored_parents, correct_parents) in bad_parents:
222
# XXX not ready for id join/split operations.
223
weave_id = text_key[0]
224
revision_id = text_key[-1]
225
weave_parents = tuple([parent[-1] for parent in stored_parents])
226
correct_parents = tuple([parent[-1] for parent in correct_parents])
227
self.inconsistent_parents.append(
228
(revision_id, weave_id, weave_parents, correct_parents))
229
self.unreferenced_versions.update(unused_versions)
222
231
def _check_revision_tree(self, rev_id):
223
232
tree = self.repository.revision_tree(rev_id)
224
233
inv = tree.inventory
236
for path, ie in inv.iter_entries():
237
self._add_entry_to_text_key_references(inv, ie)
227
239
if file_id in seen_ids:
228
240
raise BzrCheckError('duplicated file_id {%s} '
229
241
'in inventory for revision {%s}'
230
242
% (file_id, rev_id))
231
seen_ids[file_id] = True
243
seen_ids.add(file_id)
234
244
ie.check(self, rev_id, inv, tree)
236
for path, ie in inv.iter_entries():
237
245
if path in seen_names:
238
246
raise BzrCheckError('duplicated path %s '
239
247
'in inventory for revision {%s}'
240
248
% (path, rev_id))
241
seen_names[path] = True
251
def _add_entry_to_text_key_references(self, inv, entry):
252
if not self.rich_roots and entry == inv.root:
254
key = (entry.file_id, entry.revision)
255
self.text_key_references.setdefault(key, False)
256
if entry.revision == inv.revision_id:
257
self.text_key_references[key] = True
260
@deprecated_function(deprecated_in((1,6,0)))
244
261
def check(branch, verbose):
245
262
"""Run consistency checks on a branch.
247
Results are reported through logging.
264
Results are reported through logging.
266
Deprecated in 1.6. Please use check_branch instead.
268
:raise BzrCheckError: if there's a consistency error.
270
check_branch(branch, verbose)
273
def check_branch(branch, verbose):
274
"""Run consistency checks on a branch.
276
Results are reported through logging.
249
278
:raise BzrCheckError: if there's a consistency error.
251
280
branch.lock_read()
253
282
branch_result = branch.check()
254
repo_result = branch.repository.check([branch.last_revision()])
257
285
branch_result.report_results(verbose)
258
repo_result.report_results(verbose)
288
def check_dwim(path, verbose, do_branch=False, do_repo=False, do_tree=False):
290
tree, branch, repo, relpath = \
291
BzrDir.open_containing_tree_branch_or_repository(path)
292
except errors.NotBranchError:
293
tree = branch = repo = None
297
note("Checking working tree at '%s'."
298
% (tree.bzrdir.root_transport.base,))
301
log_error("No working tree found at specified location.")
303
if branch is not None:
306
# The branch is in a shared repository
307
repo = branch.repository
309
elif repo is not None:
310
branches = repo.find_branches(using=True)
316
note("Checking repository at '%s'."
317
% (repo.bzrdir.root_transport.base,))
318
result = repo.check()
319
result.report_results(verbose)
322
log_error("No branch found at specified location.")
324
for branch in branches:
325
note("Checking branch at '%s'."
326
% (branch.bzrdir.root_transport.base,))
327
check_branch(branch, verbose)
332
log_error("No branch found at specified location.")
334
log_error("No repository found at specified location.")