Rev 4427: The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL in http://bazaar.launchpad.net/~jameinel/bzr/1.16-chk-direct

John Arbash Meinel john at arbash-meinel.com
Thu Jun 18 19:18:56 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.16-chk-direct

------------------------------------------------------------
revno: 4427
revision-id: john at arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
parent: john at arbash-meinel.com-20090617191253-1m90zv94aimg1orm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.16-chk-direct
timestamp: Thu 2009-06-18 13:18:36 -0500
message:
  The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
  Which is completely valid, but 'broke' one of the tests.
  So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
  member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
  has to check the root keys.
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-06-17 19:10:35 +0000
+++ b/bzrlib/inventory.py	2009-06-18 18:18:36 +0000
@@ -1470,6 +1470,19 @@
         self._path_to_fileid_cache = {}
         self._search_key_name = search_key_name
 
+    def __eq__(self, other):
+        """Compare two sets by comparing their contents."""
+        if not isinstance(other, CHKInventory):
+            return NotImplemented
+
+        this_key = self.id_to_entry.key()
+        other_key = other.id_to_entry.key()
+        this_pid_key = self.parent_id_basename_to_file_id.key()
+        other_pid_key = other.parent_id_basename_to_file_id.key()
+        if None in (this_key, this_pid_key, other_key, other_pid_key):
+            return False
+        return this_key == other_key and this_pid_key == other_pid_key
+
     def _entry_to_bytes(self, entry):
         """Serialise entry as a single bytestring.
 

=== modified file 'bzrlib/tests/per_repository/test_add_inventory_by_delta.py'
--- a/bzrlib/tests/per_repository/test_add_inventory_by_delta.py	2009-04-09 20:23:07 +0000
+++ b/bzrlib/tests/per_repository/test_add_inventory_by_delta.py	2009-06-18 18:18:36 +0000
@@ -47,8 +47,17 @@
 
     def make_inv_delta(self, old, new):
         """Make an inventory delta from two inventories."""
-        old_ids = set(old._byid.iterkeys())
-        new_ids = set(new._byid.iterkeys())
+        by_id = getattr(old, '_byid', None)
+        if by_id is None:
+            old_ids = set(entry.file_id for entry in old.iter_just_entries())
+        else:
+            old_ids = set(by_id)
+        by_id = getattr(new, '_byid', None)
+        if by_id is None:
+            new_ids = set(entry.file_id for entry in new.iter_just_entries())
+        else:
+            new_ids = set(by_id)
+
         adds = new_ids - old_ids
         deletes = old_ids - new_ids
         common = old_ids.intersection(new_ids)
@@ -68,7 +77,11 @@
         # validator.
         tree = self.make_branch_and_tree('tree')
         revid = tree.commit("empty post")
-        revtree = tree.basis_tree()
+        # tree.basis_tree() always uses a plain Inventory from the dirstate, we
+        # want the same format inventory as we have in the repository
+        revtree = tree.branch.repository.revision_tree(
+                    tree.branch.last_revision())
+        tree.basis_tree()
         revtree.lock_read()
         self.addCleanup(revtree.unlock)
         new_inv = revtree.inventory



More information about the bazaar-commits mailing list