Rev 3171: Add a test to Repository.deserialise_inventory that the resulting ivnentory is the one asked for, and update relevant tests. Also tweak the model 1 to 2 regenerate inventories logic to use the revision trees parent marker which is more accurate in some cases. in http://people.ubuntu.com/~robertc/baz2.0/iter_inventories

Robert Collins robertc at robertcollins.net
Wed Jan 9 00:51:09 GMT 2008


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

------------------------------------------------------------
revno: 3171
revision-id:robertc at robertcollins.net-20080109005101-mmpiihes7sw3uzr5
parent: robertc at robertcollins.net-20080107012738-p74oqa65zc0z2xrr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: iter_inventories
timestamp: Wed 2008-01-09 11:51:01 +1100
message:
  Add a test to Repository.deserialise_inventory that the resulting ivnentory is the one asked for, and update relevant tests. Also tweak the model 1 to 2 regenerate inventories logic to use the revision trees parent marker which is more accurate in some cases.
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
  bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
  bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-12-22 00:03:14 +0000
+++ b/bzrlib/bzrdir.py	2008-01-09 00:51:01 +0000
@@ -2040,7 +2040,7 @@
     def _load_updated_inventory(self, rev_id):
         assert rev_id in self.converted_revs
         inv_xml = self.inv_weave.get_text(rev_id)
-        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml)
+        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
         return inv
 
     def _convert_one_rev(self, rev_id):

=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2007-11-21 03:35:07 +0000
+++ b/bzrlib/fetch.py	2008-01-09 00:51:01 +0000
@@ -362,9 +362,8 @@
         stored in the target (reserializing it in a different format).
         :param revs: The revisions to include
         """
-        inventory_weave = self.source.get_inventory_weave()
         for tree in self.iter_rev_trees(revs):
-            parents = inventory_weave.get_parents(tree.get_revision_id())
+            parents = tree.get_parent_ids()
             self.target.add_inventory(tree.get_revision_id(), tree.inventory,
                                       parents)
 
@@ -372,7 +371,7 @@
 class Model1toKnit2Fetcher(GenericRepoFetcher):
     """Fetch from a Model1 repository into a Knit2 repository
     """
-    def __init__(self, to_repository, from_repository, last_revision=None, 
+    def __init__(self, to_repository, from_repository, last_revision=None,
                  pb=None):
         self.helper = Inter1and2Helper(from_repository, to_repository)
         GenericRepoFetcher.__init__(self, to_repository, from_repository,

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-01-07 01:27:38 +0000
+++ b/bzrlib/repository.py	2008-01-09 00:51:01 +0000
@@ -1479,7 +1479,9 @@
         :param revision_id: The expected revision id of the inventory.
         :param xml: A serialised inventory.
         """
-        return self._serializer.read_inventory_from_string(xml, revision_id)
+        result = self._serializer.read_inventory_from_string(xml, revision_id)
+        assert result.revision_id == revision_id
+        return result
 
     def serialise_inventory(self, inv):
         return self._serializer.write_inventory_to_string(inv)

=== modified file 'bzrlib/tests/interrepository_implementations/test_interrepository.py'
--- a/bzrlib/tests/interrepository_implementations/test_interrepository.py	2007-11-30 22:13:29 +0000
+++ b/bzrlib/tests/interrepository_implementations/test_interrepository.py	2008-01-09 00:51:01 +0000
@@ -262,24 +262,6 @@
         to_repo = self.make_to_repository('to')
         to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0])
 
-    def test_fetch_no_inventory_revision(self):
-        """Old inventories lack revision_ids, so simulate this"""
-        from_tree = self.make_branch_and_tree('tree')
-        if sys.platform == 'win32':
-            from_repo = from_tree.branch.repository
-            check_repo_format_for_funky_id_on_win32(from_repo)
-        self.build_tree(['tree/filename'])
-        from_tree.add('filename', 'funky-chars<>%&;"\'')
-        from_tree.commit('commit filename')
-        old_deserialise = from_tree.branch.repository.deserialise_inventory
-        def deserialise(revision_id, text):
-            inventory = old_deserialise(revision_id, text)
-            inventory.revision_id = None
-            return inventory
-        from_tree.branch.repository.deserialise_inventory = deserialise
-        to_repo = self.make_to_repository('to')
-        to_repo.fetch(from_tree.branch.repository, from_tree.last_revision())
-
 
 class TestCaseWithComplexRepository(TestCaseWithInterRepository):
 

=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py	2007-12-30 18:20:15 +0000
+++ b/bzrlib/tests/test_repository.py	2008-01-09 00:51:01 +0000
@@ -398,7 +398,9 @@
         # Arguably, the deserialise_inventory should detect a mismatch, and
         # raise an error, rather than silently using one revision_id over the
         # other.
-        inv = repo.deserialise_inventory('test-rev-id', inv_xml)
+        self.assertRaises(AssertionError, repo.deserialise_inventory,
+            'test-rev-id', inv_xml)
+        inv = repo.deserialise_inventory('other-rev-id', inv_xml)
         self.assertEqual('other-rev-id', inv.root.revision)
 
 

=== modified file 'bzrlib/xml_serializer.py'
--- a/bzrlib/xml_serializer.py	2007-10-05 02:41:37 +0000
+++ b/bzrlib/xml_serializer.py	2008-01-09 00:51:01 +0000
@@ -65,7 +65,11 @@
         :param xml_string: The xml to read.
         :param revision_id: If not-None, the expected revision id of the
             inventory. Some serialisers use this to set the results' root
-            revision.
+            revision. This should be supplied for deserialising all
+            from-repository inventories so that xml5 inventories that were
+            serialised without a revision identifier can be given the right
+            revision id (but not for working tree inventories where users can
+            edit the data without triggering checksum errors or anything).
         """
         try:
             return self._unpack_inventory(fromstring(xml_string), revision_id)



More information about the bazaar-commits mailing list