Rev 4603: Add a test that inventory texts are preserved during pack. in http://bazaar.launchpad.net/~jameinel/bzr/1.19-bug-402778

John Arbash Meinel john at arbash-meinel.com
Wed Aug 12 19:49:33 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.19-bug-402778

------------------------------------------------------------
revno: 4603
revision-id: john at arbash-meinel.com-20090812184922-476warqp95cy635v
parent: john at arbash-meinel.com-20090812022106-02s82dc18wqnhyyo
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.19-bug-402778
timestamp: Wed 2009-08-12 13:49:22 -0500
message:
  Add a test that inventory texts are preserved during pack.
  Rename test_pack_repository => per_pack_repository since it is an implementations test.
  This should also fix the earlier test failures.
-------------- next part --------------
=== modified file 'bzrlib/repofmt/groupcompress_repo.py'
--- a/bzrlib/repofmt/groupcompress_repo.py	2009-08-04 04:36:34 +0000
+++ b/bzrlib/repofmt/groupcompress_repo.py	2009-08-12 18:49:22 +0000
@@ -410,7 +410,13 @@
 
     def _copy_inventory_texts(self):
         source_vf, target_vf = self._build_vfs('inventory', True, True)
-        self._copy_stream(source_vf, target_vf, self.revision_keys,
+        # It is not sufficient to just use self.revision_keys, as stacked
+        # repositories can have more inventories than they have revisions.
+        # One alternative would be to do something with
+        # get_parent_map(self.revision_keys), but that shouldn't be any faster
+        # than this.
+        inventory_keys = source_vf.keys()
+        self._copy_stream(source_vf, target_vf, inventory_keys,
                           'inventories', self._get_filtered_inv_stream, 2)
 
     def _copy_chk_texts(self):
@@ -1110,7 +1116,7 @@
 
 class RepositoryFormat2a(RepositoryFormatCHK2):
     """A CHK repository that uses the bencode revision serializer.
-    
+
     This is the same as RepositoryFormatCHK2 but with a public name.
     """
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-08-04 11:40:59 +0000
+++ b/bzrlib/tests/__init__.py	2009-08-12 18:49:22 +0000
@@ -3386,6 +3386,7 @@
                    'bzrlib.tests.per_lock',
                    'bzrlib.tests.per_transport',
                    'bzrlib.tests.per_tree',
+                   'bzrlib.tests.per_pack_repository',
                    'bzrlib.tests.per_repository',
                    'bzrlib.tests.per_repository_chk',
                    'bzrlib.tests.per_repository_reference',
@@ -3480,7 +3481,6 @@
                    'bzrlib.tests.test_osutils',
                    'bzrlib.tests.test_osutils_encodings',
                    'bzrlib.tests.test_pack',
-                   'bzrlib.tests.test_pack_repository',
                    'bzrlib.tests.test_patch',
                    'bzrlib.tests.test_patches',
                    'bzrlib.tests.test_permissions',

=== renamed file 'bzrlib/tests/test_pack_repository.py' => 'bzrlib/tests/per_pack_repository.py'
--- a/bzrlib/tests/test_pack_repository.py	2009-07-17 10:38:41 +0000
+++ b/bzrlib/tests/per_pack_repository.py	2009-08-12 18:49:22 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -295,6 +295,41 @@
         self.assertEqual(1, len(list(index.iter_all_entries())))
         self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
 
+    def test_pack_preserves_all_inventories(self):
+        # This is related to bug:
+        #   https://bugs.launchpad.net/bzr/+bug/412198
+        # Stacked repositories need to keep the inventory for parents, even
+        # after a pack operation. However, it is harder to test that, then just
+        # test that all inventory texts are preserved.
+        format = self.get_format()
+        builder = self.make_branch_builder('source', format=format)
+        builder.start_series()
+        builder.build_snapshot('A-id', None, [
+            ('add', ('', 'root-id', 'directory', None))])
+        builder.build_snapshot('B-id', None, [
+            ('add', ('file', 'file-id', 'file', 'B content\n'))])
+        builder.build_snapshot('C-id', None, [
+            ('modify', ('file-id', 'C content\n'))])
+        builder.finish_series()
+        b = builder.get_branch()
+        b.lock_read()
+        self.addCleanup(b.unlock)
+        repo = self.make_repository('repo', shared=True, format=format)
+        repo.lock_write()
+        self.addCleanup(repo.unlock)
+        repo.fetch(b.repository, revision_id='B-id')
+        inv = b.repository.iter_inventories(['C-id']).next()
+        repo.start_write_group()
+        repo.add_inventory('C-id', inv, ['B-id'])
+        repo.commit_write_group()
+        self.assertEqual([('A-id',), ('B-id',), ('C-id',)],
+                         sorted(repo.inventories.keys()))
+        repo.pack()
+        self.assertEqual([('A-id',), ('B-id',), ('C-id',)],
+                         sorted(repo.inventories.keys()))
+        # Content should be preserved as well
+        self.assertEqual(inv, repo.iter_inventories(['C-id']).next())
+
     def test_pack_layout(self):
         # Test that the ordering of revisions in pack repositories is
         # tip->ancestor
@@ -808,7 +843,7 @@
                 matching_format_name = 'pack-0.92-subtree'
             else:
                 if repo._format.supports_chks:
-                    matching_format_name = 'development6-rich-root'
+                    matching_format_name = '2a'
                 else:
                     matching_format_name = 'rich-root-pack'
             mismatching_format_name = 'pack-0.92'
@@ -841,7 +876,7 @@
         else:
             if repo.supports_rich_root():
                 if repo._format.supports_chks:
-                    matching_format_name = 'development6-rich-root'
+                    matching_format_name = '2a'
                 else:
                     matching_format_name = 'rich-root-pack'
                 mismatching_format_name = 'pack-0.92-subtree'
@@ -1060,9 +1095,9 @@
                   "(bzr 1.9)\n",
               format_supports_external_lookups=True,
               index_class=BTreeGraphIndex),
-         dict(format_name='development6-rich-root',
-              format_string='Bazaar development format - group compression '
-                  'and chk inventory (needs bzr.dev from 1.14)\n',
+         dict(format_name='2a',
+              format_string="Bazaar repository format 2a "
+                "(needs bzr 1.16 or later)\n",
               format_supports_external_lookups=True,
               index_class=BTreeGraphIndex),
          ]



More information about the bazaar-commits mailing list