Rev 2665: Fugly version to remove signatures.kndx in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Wed Jul 18 05:31:32 BST 2007


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

------------------------------------------------------------
revno: 2665
revision-id: robertc at robertcollins.net-20070718043129-ugp98g3fsuzh6sak
parent: robertc at robertcollins.net-20070718034026-d3ado6wvo5lkma58
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Wed 2007-07-18 14:31:29 +1000
message:
  Fugly version to remove signatures.kndx
modified:
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/store/revision/knit.py  knit.py-20060303020652-de5fa299e941a3c7
  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/index.py'
--- a/bzrlib/index.py	2007-07-15 15:40:37 +0000
+++ b/bzrlib/index.py	2007-07-18 04:31:29 +0000
@@ -365,8 +365,12 @@
 
         :param nodes: An iterable of (key, node_refs, value) entries to add.
         """
-        for (key, value, node_refs) in nodes:
-            self.add_node(key, value, node_refs)
+        if self.reference_lists:
+            for (key, value, node_refs) in nodes:
+                self.add_node(key, value, node_refs)
+        else:
+            for (key, value) in nodes:
+                self.add_node(key, value)
 
     def iter_all_entries(self):
         """Iterate over all keys within the index

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2007-07-18 03:40:26 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-07-18 04:31:29 +0000
@@ -321,14 +321,12 @@
         self.repo = repo
         self._serializer = revisionstore._serializer
 
-    def _add_revision(self, revision, revision_as_file, transaction):
-        """Template method helper to store revision in this store."""
-        # FIXME: make this ghost aware at the knit level
-        rf = self.get_revision_file(transaction)
-        self.get_revision_file(transaction).add_lines_with_ghosts(
-            revision.revision_id,
-            revision.parent_ids,
-            osutils.split_lines(revision_as_file.read()))
+    def _ensure_names_loaded(self):
+        if self.repo._revision_indices is None:
+            index_transport = self.get_indices_transport()
+            self.repo._revision_indices = file_collection.FileCollection(
+                index_transport, 'index')
+            self.repo._revision_indices.load()
 
     def get_indices_transport(self):
         return self.versioned_file_store._transport.clone('indices')
@@ -338,20 +336,17 @@
         if getattr(self.repo, '_revision_knit', None) is not None:
             return self.repo._revision_knit
         index_transport = self.get_indices_transport()
-        self.repo._revision_indices = file_collection.FileCollection(
-            index_transport, 'index')
-        self.repo._revision_indices.load()
         indices = []
+        self._ensure_names_loaded()
         def _cmp(x, y): return cmp(int(x), int(y))
         for name in sorted(self.repo._revision_indices.names(), cmp=_cmp, reverse=True):
             # TODO: maybe this should expose size to us  to allow
             # sorting of the indices for better performance ?
-            index_name = self.name_to_index_name(name)
+            index_name = self.name_to_revision_index_name(name)
             indices.append(GraphIndex(index_transport, index_name))
-        if self.repo.control_files._lock_mode == 'w':
+        if self.repo.is_in_write_group():
             # allow writing: queue writes to a new index
-            indices.append(InMemoryGraphIndex(1))
-            self.repo._revision_write_index = indices[-1]
+            indices.append(self.repo._revision_write_index)
             add_callback = self.repo._revision_write_index.add_nodes
         else:
             add_callback = None # no data-adding permitted.
@@ -365,33 +360,106 @@
             index=knit_index, delta=False, factory=knit.KnitPlainFactory())
         return self.repo._revision_knit
 
+    def get_signature_file(self, transaction):
+        """Get the signature versioned file object."""
+        if getattr(self.repo, '_signature_knit', None) is not None:
+            return self.repo._signature_knit
+        index_transport = self.get_indices_transport()
+        indices = []
+        self._ensure_names_loaded()
+        def _cmp(x, y): return cmp(int(x), int(y))
+        for name in sorted(self.repo._revision_indices.names(), cmp=_cmp, reverse=True):
+            # TODO: maybe this should expose size to us  to allow
+            # sorting of the indices for better performance ?
+            index_name = self.name_to_signature_index_name(name)
+            indices.append(GraphIndex(index_transport, index_name))
+        if self.repo.is_in_write_group():
+            # allow writing: queue writes to a new index
+            indices.append(self.repo._signature_write_index)
+            add_callback = self.repo._signature_write_index.add_nodes
+        else:
+            add_callback = None # no data-adding permitted.
+        self.repo._signature_all_indices = CombinedGraphIndex(indices)
+        knit_index = KnitGraphIndex(self.repo._signature_all_indices,
+            add_callback=add_callback, parents=False)
+        self.repo._signature_knit = knit.KnitVersionedFile(
+            'signatures', index_transport.clone('..'),
+            self.repo.control_files._file_mode,
+            create=False, access_mode=self.repo.control_files._lock_mode,
+            index=knit_index, delta=False, factory=knit.KnitPlainFactory())
+        return self.repo._signature_knit
+
     def flush(self):
         """Write out pending indices."""
-        # have we done anything?
-        if getattr(self.repo, '_revision_knit', None) is not None:
-            index_transport = self.get_indices_transport()
+        # if any work has been done, allocate a new name
+        if (getattr(self.repo, '_revision_knit', None) is not None or
+            getattr(self.repo, '_signature_knit', None) is not None):
             new_name = self.repo._revision_indices.allocate()
-            new_index_name = self.name_to_index_name(new_name)
-            index_transport.put_file(new_index_name,
-                self.repo._revision_write_index.finish())
             self.repo._revision_indices.save()
-            self.repo._revision_write_index = None
+        else:
+            # no knits actually accessed
+            return
+        index_transport = self.get_indices_transport()
+        # write a revision index (might be empty)
+        new_index_name = self.name_to_revision_index_name(new_name)
+        index_transport.put_file(new_index_name,
+            self.repo._revision_write_index.finish())
+        self.repo._revision_write_index = None
+        if self.repo._revision_all_indices is not None:
+            # revisions 'knit' accessed : update it.
             self.repo._revision_all_indices.insert_index(0,
                 GraphIndex(index_transport, new_index_name))
             # remove the write buffering index. XXX: API break
             # - clearly we need a remove_index call too.
             del self.repo._revision_all_indices._indices[-1]
+        # write a signatures index (might be empty)
+        new_index_name = self.name_to_signature_index_name(new_name)
+        index_transport.put_file(new_index_name,
+            self.repo._signature_write_index.finish())
+        self.repo._signature_write_index = None
+        if self.repo._signature_all_indices is not None:
+            # sigatures 'knit' accessed : update it.
+            self.repo._signature_all_indices.insert_index(0,
+                GraphIndex(index_transport, new_index_name))
+            # remove the write buffering index. XXX: API break
+            # - clearly we need a remove_index call too.
+            del self.repo._signature_all_indices._indices[-1]
 
-    def name_to_index_name(self, name):
+    def name_to_revision_index_name(self, name):
         """The revision index is the name + .rix."""
         return name + '.rix'
 
+    def name_to_signature_index_name(self, name):
+        """The signature index is the name + .six."""
+        return name + '.six'
+
     def reset(self):
         """Clear all cached data."""
+        # the packs that exist
+        self.repo._revision_indices = None
+        # cached revision data
         self.repo._revision_knit = None
-        self.repo._revision_indices = None
         self.repo._revision_write_index = None
         self.repo._revision_all_indices = None
+        # cached signature data
+        self.repo._signature_knit = None
+        self.repo._signature_write_index = None
+        self.repo._signature_all_indices = None
+
+    def setup(self):
+        # setup in-memory indices to accumulate data.
+        if self.repo.control_files._lock_mode != 'w':
+            raise errors.NotWriteLocked(self)
+        self.repo._revision_write_index = InMemoryGraphIndex(1)
+        self.repo._signature_write_index = InMemoryGraphIndex(0)
+        # if knit indices have been handed out, add a mutable
+        # index to them
+        if self.repo._revision_knit is not None:
+            self.repo._revision_all_indices.insert_index(0, self.repo._revision_write_index)
+            self.repo._revision_knit._index._add_callback = self.repo._revision_write_index.add_nodes
+        if self.repo._signature_knit is not None:
+            self.repo._signature_all_indices.insert_index(0, self.repo._signature_write_index)
+            self.repo._signature_knit._index._add_callback = self.repo._signature_write_index.add_nodes
 
 
 class GraphKnitRepository1(KnitRepository):
@@ -412,7 +480,7 @@
             self._revision_store.reset()
 
     def _start_write_group(self):
-        pass
+        self._revision_store.setup()
 
     def _commit_write_group(self):
         self._revision_store.flush()
@@ -437,7 +505,7 @@
             self._revision_store.reset()
 
     def _start_write_group(self):
-        pass
+        self._revision_store.setup()
 
     def _commit_write_group(self):
         self._revision_store.flush()
@@ -695,6 +763,7 @@
     collection.initialise()
     collection.save()
     repo_transport.delete('revisions.kndx')
+    repo_transport.delete('signatures.kndx')
 
 
 class RepositoryFormatGraphKnit3(RepositoryFormatKnit3):

=== modified file 'bzrlib/store/revision/knit.py'
--- a/bzrlib/store/revision/knit.py	2007-07-10 21:18:54 +0000
+++ b/bzrlib/store/revision/knit.py	2007-07-18 04:31:29 +0000
@@ -65,7 +65,6 @@
     def _add_revision(self, revision, revision_as_file, transaction):
         """Template method helper to store revision in this store."""
         # FIXME: make this ghost aware at the knit level
-        rf = self.get_revision_file(transaction)
         self.get_revision_file(transaction).add_lines_with_ghosts(
             revision.revision_id,
             revision.parent_ids,

=== modified file 'bzrlib/tests/repository_implementations/test_repository.py'
--- a/bzrlib/tests/repository_implementations/test_repository.py	2007-07-18 03:40:26 +0000
+++ b/bzrlib/tests/repository_implementations/test_repository.py	2007-07-18 04:31:29 +0000
@@ -262,7 +262,11 @@
         wt = self.make_branch_and_tree('source')
         wt.commit('A', allow_pointless=True, rev_id='A')
         repo = wt.branch.repository
+        repo.lock_write()
+        repo.start_write_group()
         repo.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
+        repo.commit_write_group()
+        repo.unlock()
         old_signature = repo.get_signature_text('A')
         try:
             old_format = bzrdir.BzrDirFormat.get_default_format()

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-07-16 07:29:32 +0000
+++ b/bzrlib/tests/test_repository.py	2007-07-18 04:31:29 +0000
@@ -542,9 +542,9 @@
         """check knit content for a repository."""
         self.assertHasKndx(t, 'inventory')
         self.assertHasKnit(t, 'inventory')
-        self.assertHasKnit(t, 'revisions')
         self.assertHasNoKndx(t, 'revisions')
-        self.assertHasKndx(t, 'signatures')
+        self.assertHasKnit(t, 'revisions')
+        self.assertHasNoKndx(t, 'signatures')
         self.assertHasKnit(t, 'signatures')
         # revision-indexes file-container directory
         collection = FileCollection(t.clone('indices'), 'index')
@@ -600,6 +600,16 @@
         tree.commit('foobarbaz')
         self.assertTrue(trans.has('indices/0.rix'))
 
+    def test_add_revision_creates_zero_dot_six(self):
+        """Adding a revision makes a 0.six (Signature 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.six'))
+        tree.commit('foobarbaz')
+        self.assertTrue(trans.has('indices/0.six'))
+
+
 
 class TestExperimentalSubtrees(TestExperimentalNoSubtrees):
 



More information about the bazaar-commits mailing list