Rev 4424: Pull out the common 'populate this CHKInventory' code out into a helper in http://bazaar.launchpad.net/~jameinel/bzr/1.16-chk-direct

John Arbash Meinel john at arbash-meinel.com
Wed Jun 17 19:59:58 BST 2009


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

------------------------------------------------------------
revno: 4424
revision-id: john at arbash-meinel.com-20090617185949-7lfh5td7pipwp0ss
parent: john at arbash-meinel.com-20090617184126-i5u6odzoka4sk566
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.16-chk-direct
timestamp: Wed 2009-06-17 13:59:49 -0500
message:
  Pull out the common 'populate this CHKInventory' code out into a helper
  and share it between the creators.
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-06-17 18:41:26 +0000
+++ b/bzrlib/inventory.py	2009-06-17 18:59:49 +0000
@@ -1716,7 +1716,7 @@
         :param maximum_size: The CHKMap node size limit.
         :param search_key_name: The identifier for the search key function
         """
-        result = CHKInventory(search_key_name)
+        result = klass(search_key_name)
         result.revision_id = inventory.revision_id
         result.root_id = inventory.root.file_id
 
@@ -1729,19 +1729,24 @@
             p_id_key = parent_id_basename_key(entry)
             parent_id_basename_dict[p_id_key] = entry.file_id
 
-        search_key_func = chk_map.search_key_registry.get(search_key_name)
+        result._populate_from_dicts(chk_store, id_to_entry_dict,
+            parent_id_basename_dict, maximum_size=maximum_size)
+        return result
+
+    def _populate_from_dicts(self, chk_store, id_to_entry_dict,
+                             parent_id_basename_dict, maximum_size):
+        search_key_func = chk_map.search_key_registry.get(self._search_key_name)
         root_key = chk_map.CHKMap.from_dict(chk_store, id_to_entry_dict,
                    maximum_size=maximum_size, key_width=1,
                    search_key_func=search_key_func)
-        result.id_to_entry = chk_map.CHKMap(chk_store, root_key,
-                                            search_key_func)
+        self.id_to_entry = chk_map.CHKMap(chk_store, root_key,
+                                          search_key_func)
         root_key = chk_map.CHKMap.from_dict(chk_store,
                    parent_id_basename_dict,
                    maximum_size=maximum_size, key_width=2,
                    search_key_func=search_key_func)
-        result.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store,
-                                                     root_key, search_key_func)
-        return result
+        self.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store,
+                                                    root_key, search_key_func)
 
     def _parent_id_basename_key(self, entry):
         """Create a key for a entry in a parent_id_basename_to_file_id index."""

=== modified file 'bzrlib/repofmt/groupcompress_repo.py'
--- a/bzrlib/repofmt/groupcompress_repo.py	2009-06-17 18:41:26 +0000
+++ b/bzrlib/repofmt/groupcompress_repo.py	2009-06-17 18:59:49 +0000
@@ -674,7 +674,7 @@
         return self._inventory_add_lines(revision_id, parents,
             inv_lines, check_content=False)
 
-    def _create_inv_from_null(self, delta, new_revision_id):
+    def _create_inv_from_null(self, delta, revision_id):
         """This will mutate new_inv directly.
 
         This is a simplified form of create_by_apply_delta which knows that all
@@ -682,8 +682,7 @@
         """
         serializer = self._format._serializer
         new_inv = inventory.CHKInventory(serializer.search_key_name)
-        new_inv.revision_id = new_revision_id
-
+        new_inv.revision_id = revision_id
         entry_to_bytes = new_inv._entry_to_bytes
         id_to_entry_dict = {}
         parent_id_basename_dict = {}
@@ -707,20 +706,8 @@
             id_to_entry_dict[(file_id,)] = new_value
             parent_id_basename_dict[parent_id_basename_key] = file_id
 
-        search_key_func = chk_map.search_key_registry.get(
-                            serializer.search_key_name)
-        maximum_size = serializer.maximum_size
-        root_key = chk_map.CHKMap.from_dict(self.chk_bytes, id_to_entry_dict,
-                   maximum_size=maximum_size, key_width=1,
-                   search_key_func=search_key_func)
-        new_inv.id_to_entry = chk_map.CHKMap(self.chk_bytes, root_key,
-                                             search_key_func)
-        root_key = chk_map.CHKMap.from_dict(self.chk_bytes,
-                   parent_id_basename_dict,
-                   maximum_size=maximum_size, key_width=2,
-                   search_key_func=search_key_func)
-        new_inv.parent_id_basename_to_file_id = chk_map.CHKMap(self.chk_bytes,
-                                                    root_key, search_key_func)
+        new_inv._populate_from_dicts(self.chk_bytes, id_to_entry_dict,
+            parent_id_basename_dict, maximum_size=serializer.maximum_size)
         return new_inv
 
     def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,



More information about the bazaar-commits mailing list