Rev 4335: Alter Branch.check to log errors rather than raising. in http://people.ubuntu.com/~robertc/baz2.0/check

Robert Collins robertc at robertcollins.net
Fri May 8 06:10:22 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/check

------------------------------------------------------------
revno: 4335
revision-id: robertc at robertcollins.net-20090508051018-dw9xgkfd35wn7m9x
parent: robertc at robertcollins.net-20090508020636-f5w6t5ry2g1xluyo
committer: Robert Collins <robertc at robertcollins.net>
branch nick: check
timestamp: Fri 2009-05-08 15:10:18 +1000
message:
  Alter Branch.check to log errors rather than raising.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-05-05 12:55:37 +0000
+++ b/bzrlib/branch.py	2009-05-08 05:10:18 +0000
@@ -1123,22 +1123,25 @@
 
         :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:
-            raise errors.BzrCheckError('revno does not match len(mainline)'
-                ' %s != %s' % (last_revno, len(real_rev_history)))
+            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:
-                raise errors.BzrCheckError("mainline revision {%s} not in repository"
-                            % revision_id)
+                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.
@@ -1148,7 +1151,7 @@
                                         "parents of {%s}"
                                         % (mainline_parent_id, revision_id))
             mainline_parent_id = revision_id
-        return BranchCheckResult(self)
+        return result
 
     def _get_checkout_format(self):
         """Return the most suitable metadir for a checkout of this branch.
@@ -2829,6 +2832,7 @@
 
     def __init__(self, branch):
         self.branch = branch
+        self.errors = []
 
     def report_results(self, verbose):
         """Report the check results via trace.note.
@@ -2836,9 +2840,10 @@
         :param verbose: Requests more detailed display of what was checked,
             if any.
         """
-        note('checked branch %s format %s',
-             self.branch.base,
-             self.branch._format)
+        note('checked branch %s format %s', self.branch.base,
+            self.branch._format)
+        for error in self.errors:
+            note('found error:%s', error)
 
 
 class Converter5to6(object):

=== modified file 'bzrlib/tests/branch_implementations/test_check.py'
--- a/bzrlib/tests/branch_implementations/test_check.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/branch_implementations/test_check.py	2009-05-08 05:10:18 +0000
@@ -16,7 +16,9 @@
 
 """Tests for branch implementations - test check() functionality"""
 
-from bzrlib import errors
+from StringIO import StringIO
+
+from bzrlib import errors, tests, ui
 from bzrlib.tests.branch_implementations import TestCaseWithBranch
 
 
@@ -54,10 +56,11 @@
             # with set_last_revision_info
             tree.branch.set_last_revision_info(3, r5)
 
-        e = self.assertRaises(errors.BzrCheckError,
-                              tree.branch.check)
-        self.assertEqual('Internal check failed:'
-                         ' revno does not match len(mainline) 3 != 5', str(e))
+        result = tree.branch.check()
+        ui.ui_factory = tests.TestUIFactory(stdout=StringIO())
+        result.report_results(True)
+        self.assertContainsRe('revno does not match len',
+            ui.ui_factory.stdout.getvalue())
 
     def test_check_branch_report_results(self):
         """Checking a branch produces results which can be printed"""




More information about the bazaar-commits mailing list