Rev 2687: Remove inventory.kndx. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Tue Jul 31 08:12:38 BST 2007


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

------------------------------------------------------------
revno: 2687
revision-id: robertc at robertcollins.net-20070731071233-t7n74dnqs6stfpbd
parent: robertc at robertcollins.net-20070730050702-lrw04l6d2qokqlf6
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Tue 2007-07-31 17:12:33 +1000
message:
  Remove inventory.kndx.
modified:
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
  bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2007-07-20 02:38:23 +0000
+++ b/bzrlib/fetch.py	2007-07-31 07:12:33 +0000
@@ -130,9 +130,7 @@
         requested revisions, finally clearing the progress bar.
         """
         self.to_weaves = self.to_repository.weave_store
-        self.to_control = self.to_repository.control_weaves
         self.from_weaves = self.from_repository.weave_store
-        self.from_control = self.from_repository.control_weaves
         self.count_total = 0
         self.file_ids_names = {}
         pp = ProgressPhase('Fetch phase', 4, self.pb)
@@ -203,8 +201,7 @@
         pb = bzrlib.ui.ui_factory.nested_progress_bar()
         try:
             pb.update("fetch inventory", 0, 2)
-            to_weave = self.to_control.get_weave('inventory',
-                    self.to_repository.get_transaction())
+            to_weave = self.to_repository.get_inventory_weave()
     
             child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
             try:

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2007-07-30 05:07:02 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-07-31 07:12:33 +0000
@@ -584,6 +584,99 @@
         # adjust them.
 
 
+class InventoryKnitThunk(object):
+    """An object to manage thunking get_inventory_weave to pack based knits."""
+
+    def __init__(self, repo, transport):
+        """Create an InventoryKnitThunk for repo at transport.
+
+        This will store its state in the Repository, use the
+        indices FileNames to provide a KnitGraphIndex,
+        and at the end of transactions write a new index..
+        """
+        self.repo = repo
+        self.transport = transport
+
+    def data_inserted(self):
+        # XXX: Should we define __len__ for indices?
+        if (getattr(self.repo, '_inv_write_index', None) and
+            len(list(self.repo._inv_write_index.iter_all_entries()))):
+            return True
+
+    def _ensure_all_index(self):
+        """Create the combined index for all inventories."""
+        if getattr(self.repo, '_inv_all_indices', None) is not None:
+            return
+        indices = []
+        self.repo._data_names.ensure_loaded()
+        for name in self.repo._data_names.names():
+            # TODO: maybe this should expose size to us  to allow
+            # sorting of the indices for better performance ?
+            index_name = self.name_to_inv_index_name(name)
+            indices.append(GraphIndex(self.transport, index_name))
+        if self.repo.is_in_write_group():
+            # allow writing: queue writes to a new index
+            indices.append(self.repo._inv_write_index)
+        self.repo._inv_all_indices = CombinedGraphIndex(indices)
+
+    def flush(self, new_name):
+        """Write the index out to new_name."""
+        # write an index (might be empty)
+        new_index_name = self.name_to_inv_index_name(new_name)
+        self.transport.put_file(new_index_name,
+            self.repo._inv_write_index.finish())
+        self.repo._inv_write_index = None
+        if self.repo._inv_all_indices is not None:
+            # inv 'knit' has been used, replace the mutated memory index
+            # with the new on-disk one. XXX: is this really a good idea?
+            # perhaps just keep using the memory one ?
+            self.repo._inv_all_indices.insert_index(0,
+                GraphIndex(self.transport, new_index_name))
+            # remove the write buffering index. XXX: API break
+            # - clearly we need a remove_index call too.
+            del self.repo._inv_all_indices._indices[-1]
+
+    def get_weave(self):
+        """Get a 'Knit' that contains inventory data."""
+        self._ensure_all_index()
+        filename = 'inventory'
+        if self.repo.is_in_write_group():
+            add_callback = self.repo._inv_write_index.add_nodes
+        else:
+            add_callback = None # no data-adding permitted.
+
+        knit_index = KnitGraphIndex(self.repo._inv_all_indices,
+            add_callback=add_callback,
+            deltas=True, parents=True)
+        # TODO - mode support. self.weavestore._file_mode,
+        return knit.KnitVersionedFile('inventory', self.transport.clone('..'),
+            index=knit_index,
+            factory=knit.KnitPlainFactory())
+
+    def name_to_inv_index_name(self, name):
+        """The inv index is the name + .iix."""
+        return name + '.iix'
+
+    def reset(self):
+        """Clear all cached data."""
+        # remove any accumlating index of inv data
+        self.repo._inv_write_index = None
+        # remove all constructed inv data indices
+        self.repo._inv_all_indices = None
+
+    def setup(self):
+        # setup in-memory indices to accumulate data.
+        # - we want to map compression only, but currently the knit code hasn't
+        # been updated enough to understand that, so we have a regular 2-list
+        # index giving parents and compression source.
+        self.repo._inv_write_index = InMemoryGraphIndex(reference_lists=2)
+        # we require that inv 'knits' be accessed from within the write 
+        # group to be able to be written to, simply because it makes this
+        # code cleaner - we don't need to track all 'open' knits and 
+        # adjust them. As the inventory knit is neither precious, nor the
+        # regular interface for data access, this seems sufficient.
+
+
 class GraphKnitRepository1(KnitRepository):
     """Experimental graph-knit using repository."""
 
@@ -595,11 +688,13 @@
         self._data_names = RepositoryDataNames(self, index_transport)
         self._revision_store = GraphKnitRevisionStore(self, index_transport, self._revision_store)
         self.weave_store = GraphKnitTextStore(self, index_transport, self.weave_store)
+        self._inv_thunk = InventoryKnitThunk(self, index_transport)
 
     def _abort_write_group(self):
         # FIXME: just drop the transient index.
         self._revision_store.reset()
         self.weave_store.reset()
+        self._inv_thunk.reset()
         # forget what names there are
         self._data_names.reset()
 
@@ -607,6 +702,7 @@
         if self.control_files._lock_count==1:
             self._revision_store.reset()
             self.weave_store.reset()
+            self._inv_thunk.reset()
             # forget what names there are
             self._data_names.reset()
 
@@ -614,21 +710,28 @@
         self._data_names.setup()
         self._revision_store.setup()
         self.weave_store.setup()
+        self._inv_thunk.setup()
 
     def _commit_write_group(self):
         data_inserted = (self._revision_store.data_inserted() or
-            self.weave_store.data_inserted())
+            self.weave_store.data_inserted() or 
+            self._inv_thunk.data_inserted())
         if data_inserted:
             new_name = self._data_names.allocate()
+            self.weave_store.flush(new_name)
+            self._inv_thunk.flush(new_name)
             self._revision_store.flush(new_name)
-            self.weave_store.flush(new_name)
             self._data_names.save()
         self._revision_store.reset()
         self.weave_store.reset()
+        self._inv_thunk.reset()
         # forget what names there are - should just refresh and deal with the
         # delta.
         self._data_names.reset()
 
+    def get_inventory_weave(self):
+        return self._inv_thunk.get_weave()
+
 
 class GraphKnitRepository3(KnitRepository3):
     """Experimental graph-knit using subtrees repository."""
@@ -641,11 +744,13 @@
         self._data_names = RepositoryDataNames(self, index_transport)
         self._revision_store = GraphKnitRevisionStore(self, index_transport, self._revision_store)
         self.weave_store = GraphKnitTextStore(self, index_transport, self.weave_store)
+        self._inv_thunk = InventoryKnitThunk(self, index_transport)
 
     def _abort_write_group(self):
         # FIXME: just drop the transient index.
         self._revision_store.reset()
         self.weave_store.reset()
+        self._inv_thunk.reset()
         # forget what names there are
         self._data_names.reset()
 
@@ -653,6 +758,7 @@
         if self.control_files._lock_count==1:
             self._revision_store.reset()
             self.weave_store.reset()
+            self._inv_thunk.reset()
             # forget what names there are
             self._data_names.reset()
 
@@ -660,21 +766,28 @@
         self._data_names.setup()
         self._revision_store.setup()
         self.weave_store.setup()
+        self._inv_thunk.setup()
 
     def _commit_write_group(self):
         data_inserted = (self._revision_store.data_inserted() or
-            self.weave_store.data_inserted())
+            self.weave_store.data_inserted() or 
+            self._inv_thunk.data_inserted())
         if data_inserted:
             new_name = self._data_names.allocate()
+            self.weave_store.flush(new_name)
+            self._inv_thunk.flush(new_name)
             self._revision_store.flush(new_name)
-            self.weave_store.flush(new_name)
             self._data_names.save()
         self._revision_store.reset()
         self.weave_store.reset()
+        self._inv_thunk.reset()
         # forget what names there are - should just refresh and deal with the
         # delta.
         self._data_names.reset()
 
+    def get_inventory_weave(self):
+        return self._inv_thunk.get_weave()
+
 
 class RepositoryFormatKnit(MetaDirRepositoryFormat):
     """Bzr repository knit format (generalized). 

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-07-30 01:50:33 +0000
+++ b/bzrlib/repository.py	2007-07-31 07:12:33 +0000
@@ -115,6 +115,7 @@
 
         returns the sha1 of the serialized inventory.
         """
+        assert self.is_in_write_group()
         revision_id = osutils.safe_revision_id(revision_id)
         _mod_revision.check_not_reserved_id(revision_id)
         assert inv.revision_id is None or inv.revision_id == revision_id, \
@@ -123,8 +124,7 @@
         assert inv.root is not None
         inv_text = self.serialise_inventory(inv)
         inv_sha1 = osutils.sha_string(inv_text)
-        inv_vf = self.control_weaves.get_weave('inventory',
-                                               self.get_transaction())
+        inv_vf = self.get_inventory_weave()
         self._inventory_add_lines(inv_vf, revision_id, parents,
                                   osutils.split_lines(inv_text))
         return inv_sha1

=== modified file 'bzrlib/tests/repository_implementations/test_repository.py'
--- a/bzrlib/tests/repository_implementations/test_repository.py	2007-07-30 05:07:02 +0000
+++ b/bzrlib/tests/repository_implementations/test_repository.py	2007-07-31 07:12:33 +0000
@@ -285,13 +285,6 @@
         new_signature = wt.branch.repository.get_signature_text('A')
         self.assertEqual(old_signature, new_signature)
 
-    def test_exposed_versioned_files_are_marked_dirty(self):
-        repo = self.make_repository('.')
-        repo.lock_write()
-        inv = repo.get_inventory_weave()
-        repo.unlock()
-        self.assertRaises(errors.OutSideTransaction, inv.add_lines, 'foo', [], [])
-
     def test_format_description(self):
         repo = self.make_repository('.')
         text = repo._format.get_format_description()
@@ -596,10 +589,16 @@
 
     def test_reserved_id(self):
         repo = self.make_repository('repository')
-        self.assertRaises(errors.ReservedId, repo.add_inventory, 'reserved:',
-                          None, None)
-        self.assertRaises(errors.ReservedId, repo.add_revision, 'reserved:',
-                          None)
+        repo.lock_write()
+        repo.start_write_group()
+        try:
+            self.assertRaises(errors.ReservedId, repo.add_inventory, 'reserved:',
+                              None, None)
+            self.assertRaises(errors.ReservedId, repo.add_revision, 'reserved:',
+                              None)
+        finally:
+            repo.abort_write_group()
+            repo.unlock()
 
 
 class TestCaseWithCorruptRepository(TestCaseWithRepository):

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-07-30 05:07:02 +0000
+++ b/bzrlib/tests/test_repository.py	2007-07-31 07:12:33 +0000
@@ -540,7 +540,7 @@
 
     def check_databases(self, t):
         """check knit content for a repository."""
-        self.assertHasKndx(t, 'inventory')
+        self.assertHasNoKndx(t, 'inventory')
         self.assertHasKnit(t, 'inventory')
         self.assertHasNoKndx(t, 'revisions')
         self.assertHasKnit(t, 'revisions')
@@ -609,6 +609,15 @@
         tree.commit('foobarbaz')
         self.assertTrue(trans.has('indices/0.six'))
 
+    def test_add_revision_creates_zero_dot_iix(self):
+        """Adding a revision makes a 0.iix (Inventory IndeX) file."""
+        format = self.get_format()
+        tree = self.make_branch_and_tree('.', format=format)
+        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
+        self.assertFalse(trans.has('indices/0.iix'))
+        tree.commit('foobarbaz')
+        self.assertTrue(trans.has('indices/0.iix'))
+
     def test_add_revision_creates_zero_dot_tix(self):
         """Adding a revision makes a 0.tix (Text IndeX) file."""
         format = self.get_format()
@@ -624,6 +633,7 @@
         tree2 = self.make_branch_and_tree('2', format=format)
         tree1.branch.repository.fetch(tree2.branch.repository)
         trans = tree1.branch.repository.bzrdir.get_repository_transport(None)
+        self.assertFalse(trans.has('indices/0.iix'))
         self.assertFalse(trans.has('indices/0.rix'))
         self.assertFalse(trans.has('indices/0.six'))
         self.assertFalse(trans.has('indices/0.tix'))



More information about the bazaar-commits mailing list