Rev 4022: Polish the KnitVersionedFiles.scan_unvalidated_index api. in http://people.ubuntu.com/~robertc/baz2.0/scan-index

Robert Collins robertc at robertcollins.net
Fri Feb 20 00:43:42 GMT 2009


At http://people.ubuntu.com/~robertc/baz2.0/scan-index

------------------------------------------------------------
revno: 4022
revision-id: robertc at robertcollins.net-20090220004338-ctqo5e5hhbbkk25v
parent: andrew.bennetts at canonical.com-20090219035237-o147dwr881zgd71d
committer: Robert Collins <robertc at robertcollins.net>
branch nick: scan-index
timestamp: Fri 2009-02-20 11:43:38 +1100
message:
  Polish the KnitVersionedFiles.scan_unvalidated_index api.
=== modified file 'NEWS'
--- a/NEWS	2009-02-15 22:56:22 +0000
+++ b/NEWS	2009-02-20 00:43:38 +0000
@@ -52,6 +52,12 @@
       command object before the command is run (or help generated from
       it), without overriding the command. (Robert Collins)
 
+    * The ``_index`` of ``KnitVersionedFiles`` now supports the ability
+      to scan an underlying index that is going to be incorporated into
+      the ``KnitVersionedFiles`` object, to determine if it has missing
+      delta references. The method is ``scan_unvalidated_index``.
+      (Andrew Bennetts, Robert Collins)
+
 
 bzr 1.12 "1234567890" 2009-02-13
 --------------------------------

=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2009-02-18 05:40:39 +0000
+++ b/bzrlib/index.py	2009-02-20 00:43:38 +0000
@@ -435,7 +435,7 @@
             # there must be one line - the empty trailer line.
             raise errors.BadIndexData(self)
 
-    def external_references(self, ref_list_num=None):
+    def external_references(self, ref_list_num):
         """Return references that are not present in this index.
         """
         self._buffer_all()

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2009-02-19 03:49:50 +0000
+++ b/bzrlib/knit.py	2009-02-20 00:43:38 +0000
@@ -1883,11 +1883,15 @@
 
     def scan_unvalidated_index(self, graph_index):
         """See _KnitGraphIndex.scan_unvalidated_index."""
+        # Because kndx files do not support atomic insertion via separate index
+        # files, they do not support this method.
         raise NotImplementedError(self.scan_unvalidated_index)
 
     def get_missing_compression_parents(self):
         """See _KnitGraphIndex.get_missing_compression_parents."""
-        return frozenset()
+        # Because kndx files do not support atomic insertion via separate index
+        # files, they do not support this method.
+        raise NotImplementedError(self.get_missing_compression_parents)
     
     def _cache_key(self, key, options, pos, size, parent_keys):
         """Cache a version record in the history array and index cache.
@@ -2281,10 +2285,10 @@
 
         :param graph_index: A GraphIndex
         """
-        self._missing_compression_parents.update(
-            graph_index.external_references(ref_list_num=1))
-        self._missing_compression_parents.difference_update(
-            self.get_parent_map(self._missing_compression_parents))
+        if self._deltas:
+            new_missing = graph_index.external_references(ref_list_num=1)
+            new_missing.difference_update(self.get_parent_map(new_missing))
+            self._missing_compression_parents.update(new_missing)
 
     def get_missing_compression_parents(self):
         """Return the keys of compression parents missing from unvalidated

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2009-02-19 03:37:40 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2009-02-20 00:43:38 +0000
@@ -1805,6 +1805,20 @@
         self.repo._text_knit = None
 
     def _commit_write_group(self):
+        all_missing = set()
+        for prefix, versioned_file in (
+                ('revisions', self.repo.revisions),
+                ('inventories', self.repo.inventories),
+                ('texts', self.repo.texts),
+                ('signatures', self.repo.signatures),
+                ):
+            # We use KnitVersionedFiles exclusively so can rely on _index.
+            missing = versioned_file._index.get_missing_compression_parents()
+            all_missing.update([(prefix,) + key for key in missing])
+        if all_missing:
+            raise errors.BzrCheckError(
+                "Repository %s has missing compression parent(s) %r "
+                 % (self.repo, sorted(all_missing)))
         self._remove_pack_indices(self._new_pack)
         if self._new_pack.data_inserted():
             # get all the data to disk and read to use
@@ -1971,13 +1985,6 @@
         self._pack_collection._start_write_group()
 
     def _commit_write_group(self):
-        vfs = [self.revisions, self.inventories, self.texts, self.signatures]
-        for vf in vfs:
-            missing = vf._index.get_missing_compression_parents()
-            if missing:
-                raise errors.BzrCheckError(
-                    "Repository %s has missing compression parent(s) %r "
-                    "in %r" % (self, list(missing), vf))
         return self._pack_collection._commit_write_group()
 
     def get_transaction(self):

=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py	2009-02-18 05:40:39 +0000
+++ b/bzrlib/tests/test_index.py	2009-02-20 00:43:38 +0000
@@ -954,8 +954,6 @@
         self.assertEqual(set([]), index.external_references(0))
 
 
-
-
 class TestCombinedGraphIndex(TestCaseWithMemoryTransport):
 
     def make_index(self, name, ref_lists=0, key_elements=1, nodes=[]):

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2009-02-19 03:52:37 +0000
+++ b/bzrlib/tests/test_knit.py	2009-02-20 00:43:38 +0000
@@ -1243,9 +1243,8 @@
         self.assertRaises(
             NotImplementedError, index.scan_unvalidated_index,
             'dummy graph_index')
-        # Because scan_unvalidated_index is not implemented,
-        # get_missing_compression_parents can only return an empty set.
-        self.assertEqual(frozenset(), index.get_missing_compression_parents())
+        self.assertRaises(
+            NotImplementedError, index.get_missing_compression_parents)
 
     def test_short_line(self):
         transport = MockTransport([
@@ -1626,14 +1625,14 @@
     def test_add_good_unvalidated_index(self):
         unvalidated = self.make_g_index_no_external_refs()
         combined = CombinedGraphIndex([unvalidated])
-        index = _KnitGraphIndex(combined, lambda: True)
+        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
         index.scan_unvalidated_index(unvalidated)
         self.assertEqual(frozenset(), index.get_missing_compression_parents())
 
     def test_add_incomplete_unvalidated_index(self):
         unvalidated = self.make_g_index_missing_compression_parent()
         combined = CombinedGraphIndex([unvalidated])
-        index = _KnitGraphIndex(combined, lambda: True)
+        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
         index.scan_unvalidated_index(unvalidated)
         # This also checks that its only the compression parent that is
         # examined, otherwise 'ghost' would also be reported as a missing
@@ -1663,7 +1662,7 @@
         g_index_1 = self.make_new_missing_parent_g_index('one')
         g_index_2 = self.make_new_missing_parent_g_index('two')
         combined = CombinedGraphIndex([g_index_1, g_index_2])
-        index = _KnitGraphIndex(combined, lambda: True)
+        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
         index.scan_unvalidated_index(g_index_1)
         index.scan_unvalidated_index(g_index_2)
         self.assertEqual(
@@ -1680,7 +1679,7 @@
              (('child-of-one', ), ' 100 78',
               ([('parent-one',)], [('parent-one',)]))])
         combined = CombinedGraphIndex([graph_index_a, graph_index_b])
-        index = _KnitGraphIndex(combined, lambda: True)
+        index = _KnitGraphIndex(combined, lambda: True, deltas=True)
         index.scan_unvalidated_index(graph_index_a)
         index.scan_unvalidated_index(graph_index_b)
         self.assertEqual(
@@ -1699,6 +1698,14 @@
         size = trans.put_file(name, stream)
         return GraphIndex(trans, name, size)
 
+    def test_add_good_unvalidated_index(self):
+        unvalidated = self.make_g_index('unvalidated')
+        combined = CombinedGraphIndex([unvalidated])
+        index = _KnitGraphIndex(combined, lambda: True, parents=False)
+        index.scan_unvalidated_index(unvalidated)
+        self.assertEqual(frozenset(),
+            index.get_missing_compression_parents())
+
     def test_parents_deltas_incompatible(self):
         index = CombinedGraphIndex([])
         self.assertRaises(errors.KnitError, _KnitGraphIndex, lambda:True,




More information about the bazaar-commits mailing list