Rev 4347: Keep an ancestors dict in check rather than recreating one multiple times. in http://people.ubuntu.com/~robertc/baz2.0/check

Robert Collins robertc at robertcollins.net
Tue May 12 05:21:21 BST 2009


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

------------------------------------------------------------
revno: 4347
revision-id: robertc at robertcollins.net-20090512042117-nnqulvunpdh3ecd7
parent: robertc at robertcollins.net-20090512040112-xrf2iyh2rv6nre77
committer: Robert Collins <robertc at robertcollins.net>
branch nick: check
timestamp: Tue 2009-05-12 14:21:17 +1000
message:
  Keep an ancestors dict in check rather than recreating one multiple times.
=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py	2009-05-11 03:48:49 +0000
+++ b/bzrlib/check.py	2009-05-12 04:21:17 +0000
@@ -53,6 +53,7 @@
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import BzrCheckError
 from bzrlib.repository import Repository
+from bzrlib.revision import NULL_REVISION
 from bzrlib.symbol_versioning import deprecated_function, deprecated_in
 from bzrlib.trace import log_error, note
 import bzrlib.ui
@@ -81,6 +82,10 @@
         self.text_key_references = {}
         self.check_repo = check_repo
         self.other_results = []
+        # Ancestors map for all of revisions being checked; while large helper
+        # functions we call would create it anyway, so better to have once and
+        # keep.
+        self.ancestors = {}
 
     def check(self, callback_refs=None, check_repo=True):
         if callback_refs is None:
@@ -256,6 +261,7 @@
                 else:
                     self.ghosts.append(rev_id)
 
+        self.ancestors[rev_id] = tuple(rev.parent_ids) or (NULL_REVISION,)
         if rev.inventory_sha1:
             # Loopback - this is currently circular logic as the
             # knit get_inventory_sha1 call returns rev.inventory_sha1.
@@ -278,7 +284,8 @@
         self.progress.update('checking text storage', 1, 2)
         self.repository.texts.check(progress_bar=self.progress)
         weave_checker = self.repository._get_versioned_file_checker(
-            text_key_references=self.text_key_references)
+            text_key_references=self.text_key_references,
+            ancestors=self.ancestors)
         result = weave_checker.check_file_version_parents(
             self.repository.texts, progress_bar=self.progress)
         self.checked_weaves = weave_checker.file_ids

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2009-05-12 04:01:12 +0000
+++ b/bzrlib/repository.py	2009-05-12 04:21:17 +0000
@@ -2387,7 +2387,8 @@
                 [parents_provider, other_repository._make_parents_provider()])
         return graph.Graph(parents_provider)
 
-    def _get_versioned_file_checker(self, text_key_references=None):
+    def _get_versioned_file_checker(self, text_key_references=None,
+        ancestors=None):
         """Return an object suitable for checking versioned files.
         
         :param text_key_references: if non-None, an already built
@@ -2395,9 +2396,12 @@
             to whether they were referred to by the inventory of the
             revision_id that they contain. If None, this will be
             calculated.
+        :param ancestors: Optional result from
+            self.get_graph().get_parent_map(self.all_revision_ids()) if already
+            available.
         """
         return _VersionedFileChecker(self,
-            text_key_references=text_key_references)
+            text_key_references=text_key_references, ancestors=ancestors)
 
     def revision_ids_to_search_result(self, result_set):
         """Convert a set of revision ids to a graph SearchResult."""
@@ -3889,10 +3893,10 @@
 
 class _VersionedFileChecker(object):
 
-    def __init__(self, repository, text_key_references=None):
+    def __init__(self, repository, text_key_references=None, ancestors=None):
         self.repository = repository
         self.text_index = self.repository._generate_text_key_index(
-            text_key_references=text_key_references)
+            text_key_references=text_key_references, ancestors=ancestors)
 
     def calculate_file_version_parents(self, text_key):
         """Calculate the correct parents for a file version according to




More information about the bazaar-commits mailing list