Rev 4339: Convert Branch.check to take a refs dict as well. in http://people.ubuntu.com/~robertc/baz2.0/check
Robert Collins
robertc at robertcollins.net
Mon May 11 02:47:09 BST 2009
At http://people.ubuntu.com/~robertc/baz2.0/check
------------------------------------------------------------
revno: 4339
revision-id: robertc at robertcollins.net-20090511014706-aybf5ou226d1c6hh
parent: robertc at robertcollins.net-20090511011721-mc05o4h9bzlh62ht
committer: Robert Collins <robertc at robertcollins.net>
branch nick: check
timestamp: Mon 2009-05-11 11:47:06 +1000
message:
Convert Branch.check to take a refs dict as well.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-05-11 01:12:36 +0000
+++ b/bzrlib/branch.py 2009-05-11 01:47:06 +0000
@@ -1120,7 +1120,7 @@
target._set_all_reference_info(target_reference_dict)
@needs_read_lock
- def check(self):
+ def check(self, refs):
"""Check consistency of the branch.
In particular this checks that revisions given in the revision-history
@@ -1129,36 +1129,22 @@
Callers will typically also want to check the repository.
+ :param refs: Calculated refs for this branch as specified by
+ branch._get_check_refs()
:return: A BranchCheckResult.
"""
result = BranchCheckResult(self)
- mainline_parent_id = None
last_revno, last_revision_id = self.last_revision_info()
- real_rev_history = list(self.repository.iter_reverse_revision_history(
- last_revision_id))
- real_rev_history.reverse()
- if len(real_rev_history) != last_revno:
+ actual_revno = refs[('lefthand-distance', last_revision_id)]
+ if actual_revno != last_revno:
result.errors.append(errors.BzrCheckError(
'revno does not match len(mainline) %s != %s' % (
- last_revno, len(real_rev_history))))
- # TODO: We should probably also check that real_rev_history actually
- # matches self.revision_history()
- for revision_id in real_rev_history:
- try:
- revision = self.repository.get_revision(revision_id)
- except errors.NoSuchRevision, e:
- result.errors.append(errors.BzrCheckError(
- "mainline revision {%s} not in repository" % revision_id))
- break
- # In general the first entry on the revision history has no parents.
- # But it's not illegal for it to have parents listed; this can happen
- # in imports from Arch when the parents weren't reachable.
- if mainline_parent_id is not None:
- if mainline_parent_id not in revision.parent_ids:
- raise errors.BzrCheckError("previous revision {%s} not listed among "
- "parents of {%s}"
- % (mainline_parent_id, revision_id))
- mainline_parent_id = revision_id
+ last_revno, actual_revno)))
+ # TODO: We should probably also check that self.revision_history
+ # matches the repository for older branch formats.
+ # If looking for the code that cross-checks repository parents against
+ # the iter_reverse_revision_history output, that is now a repository
+ # specific check.
return result
def _get_checkout_format(self):
=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py 2009-05-11 01:12:36 +0000
+++ b/bzrlib/check.py 2009-05-11 01:47:06 +0000
@@ -293,7 +293,33 @@
"""
branch.lock_read()
try:
- branch_result = branch.check()
+ needed_refs = branch._get_check_refs()
+ refs = {}
+ distances = set()
+ existences = set()
+ for ref in needed_refs:
+ kind, value = ref
+ if kind == 'lefthand-distance':
+ distances.add(value)
+ elif kind == 'revision-existence':
+ existences.add(value)
+ else:
+ raise AssertionError(
+ 'unknown ref kind for ref %s' % ref)
+ node_distances = branch.repository.get_graph().find_lefthand_distances(
+ distances)
+ for key, distance in node_distances.iteritems():
+ refs[('lefthand-distance', key)] = distance
+ if key in existences and distance > 0:
+ refs[('revision-existence', key)] = True
+ existences.remove(key)
+ parent_map = branch.repository.get_graph().get_parent_map(existences)
+ for key in parent_map:
+ refs[('revision-existence', key)] = True
+ existences.remove(key)
+ for key in existences:
+ refs[('revision-existence', key)] = False
+ branch_result = branch.check(refs)
finally:
branch.unlock()
branch_result.report_results(verbose)
=== modified file 'bzrlib/tests/branch_implementations/test_check.py'
--- a/bzrlib/tests/branch_implementations/test_check.py 2009-05-11 01:12:36 +0000
+++ b/bzrlib/tests/branch_implementations/test_check.py 2009-05-11 01:47:06 +0000
@@ -56,7 +56,10 @@
# with set_last_revision_info
tree.branch.set_last_revision_info(3, r5)
- result = tree.branch.check()
+ tree.lock_read()
+ self.addCleanup(tree.unlock)
+ refs = self.make_refs(tree.branch)
+ result = tree.branch.check(refs)
ui.ui_factory = tests.TestUIFactory(stdout=StringIO())
result.report_results(True)
self.assertContainsRe('revno does not match len',
@@ -65,7 +68,9 @@
def test_check_branch_report_results(self):
"""Checking a branch produces results which can be printed"""
branch = self.make_branch('.')
- result = branch.check()
+ branch.lock_read()
+ self.addCleanup(branch.unlock)
+ result = branch.check(self.make_refs(branch))
# reports results through logging
result.report_results(verbose=True)
result.report_results(verbose=False)
@@ -76,3 +81,32 @@
self.assertEqual(
set([('revision-existence', revid), ('lefthand-distance', revid)]),
set(tree.branch._get_check_refs()))
+
+ def make_refs(self, branch):
+ needed_refs = branch._get_check_refs()
+ refs = {}
+ distances = set()
+ existences = set()
+ for ref in needed_refs:
+ kind, value = ref
+ if kind == 'lefthand-distance':
+ distances.add(value)
+ elif kind == 'revision-existence':
+ existences.add(value)
+ else:
+ raise AssertionError(
+ 'unknown ref kind for ref %s' % ref)
+ node_distances = branch.repository.get_graph().find_lefthand_distances(
+ distances)
+ for key, distance in node_distances.iteritems():
+ refs[('lefthand-distance', key)] = distance
+ if key in existences and distance > 0:
+ refs[('revision-existence', key)] = True
+ existences.remove(key)
+ parent_map = branch.repository.get_graph().get_parent_map(existences)
+ for key in parent_map:
+ refs[('revision-existence', key)] = True
+ existences.remove(key)
+ for key in existences:
+ refs[('revision-existence', key)] = False
+ return refs
More information about the bazaar-commits
mailing list