Rev 3847: Merge Ian's updates to chk_map and chk_inventory.create_by_apply_delta. in http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

John Arbash Meinel john at arbash-meinel.com
Thu Mar 5 14:46:08 GMT 2009


At http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

------------------------------------------------------------
revno: 3847
revision-id: john at arbash-meinel.com-20090305144238-dm8yf1m5s6xzstsy
parent: ian.clatworthy at canonical.com-20090302102456-ryus6notpryj0kba
parent: ian.clatworthy at internode.on.net-20090305073707-yidxduj6c12zc9td
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: brisbane-core
timestamp: Thu 2009-03-05 08:42:38 -0600
message:
  Merge Ian's updates to chk_map and chk_inventory.create_by_apply_delta.
  Do some small tweaks while we are looking at it.
modified:
  bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.8
    revision-id: ian.clatworthy at internode.on.net-20090305073707-yidxduj6c12zc9td
    parent: ian.clatworthy at internode.on.net-20090305065152-xg9v7qxnfmuyu5uf
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 17:37:07 +1000
    message:
      fix max size & key width propagation in create_by_apply_delta()
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.7
    revision-id: ian.clatworthy at internode.on.net-20090305065152-xg9v7qxnfmuyu5uf
    parent: ian.clatworthy at internode.on.net-20090305062417-1ch04h2g7eehledk
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 16:51:52 +1000
    message:
      include keywidth in repr for LeafNode
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
    ------------------------------------------------------------
    revno: 3846.1.6
    revision-id: ian.clatworthy at internode.on.net-20090305062417-1ch04h2g7eehledk
    parent: ian.clatworthy at internode.on.net-20090305060944-ss6kc13foakovo75
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 16:24:17 +1000
    message:
      more helpful deserialize assertion msg
    modified:
      bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
    ------------------------------------------------------------
    revno: 3846.1.5
    revision-id: ian.clatworthy at internode.on.net-20090305060944-ss6kc13foakovo75
    parent: ian.clatworthy at internode.on.net-20090305055838-5s2b1ut0d2ztgzng
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 16:09:44 +1000
    message:
      more efficient CHKInventory.has_id()
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.4
    revision-id: ian.clatworthy at internode.on.net-20090305055838-5s2b1ut0d2ztgzng
    parent: ian.clatworthy at internode.on.net-20090305055506-1zxsi2fog59t8pzy
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 15:58:38 +1000
    message:
      correct _entry_to_bytes() docstring
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.3
    revision-id: ian.clatworthy at internode.on.net-20090305055506-1zxsi2fog59t8pzy
    parent: ian.clatworthy at internode.on.net-20090305053527-jbdxk0hwy3rt4eaf
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 15:55:06 +1000
    message:
      improve CHKInventory docstring
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.2
    revision-id: ian.clatworthy at internode.on.net-20090305053527-jbdxk0hwy3rt4eaf
    parent: ian.clatworthy at internode.on.net-20090304051757-lar39fcmv4otbmx6
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Thu 2009-03-05 15:35:27 +1000
    message:
      fix root key handling in create_by_apply_delta()
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
    ------------------------------------------------------------
    revno: 3846.1.1
    revision-id: ian.clatworthy at internode.on.net-20090304051757-lar39fcmv4otbmx6
    parent: ian.clatworthy at canonical.com-20090302102456-ryus6notpryj0kba
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: brisbane-core
    timestamp: Wed 2009-03-04 15:17:57 +1000
    message:
      fix bug in get_mutable_inventory
    modified:
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2009-02-27 13:39:34 +0000
+++ b/bzrlib/chk_map.py	2009-03-05 14:42:38 +0000
@@ -475,7 +475,7 @@
         self._search_prefix = None
 
     def __repr__(self):
-        items_str = sorted(self._items)
+        items_str = str(sorted(self._items))
         if len(items_str) > 20:
             items_str = items_str[16] + '...]'
         return '%s(key:%s len:%s size:%s max:%s prefix:%s items:%s)' % (
@@ -557,6 +557,15 @@
         else:
             self._search_key_func = search_key_func
 
+    def __repr__(self):
+        items_str = sorted(self._items)
+        if len(items_str) > 20:
+            items_str = items_str[16] + '...]'
+        return \
+            '%s(key:%s len:%s size:%s max:%s prefix:%s keywidth:%s items:%s)' \
+            % (self.__class__.__name__, self._key, self._len, self._raw_size,
+            self._maximum_size, self._search_prefix, self._key_width, items_str)
+
     def _current_size(self):
         """Answer the current serialised size of this node.
 
@@ -607,8 +616,9 @@
             elements = line.split('\x00')
             pos += 1
             if len(elements) != width + 1:
-                raise AssertionError('Incorrect number of elements for: %s'
-                                     % (line,))
+                raise AssertionError(
+                    'Incorrect number of elements (%d vs %d) for: %r'
+                    % (len(elements), width + 1, line))
             num_value_lines = int(elements[-1])
             value_lines = lines[pos:pos+num_value_lines]
             pos += num_value_lines
@@ -745,7 +755,7 @@
             return self._search_prefix, [("", self)]
 
     def serialise(self, store):
-        """Serialise the tree to store.
+        """Serialise the LeafNode to store.
 
         :param store: A VersionedFiles honouring the CHK extensions.
         :return: An iterable of the keys inserted by this operation.
@@ -763,7 +773,7 @@
             lines.append('%s\n' % (self._common_serialised_prefix,))
             prefix_len = len(self._common_serialised_prefix)
         for key, value in sorted(self._items.items()):
-            # Add always add a final newline
+            # Always add a final newline
             value_lines = osutils.chunks_to_lines([value + '\n'])
             serialized = "%s\x00%s\n" % (self._serialise_key(key),
                                          len(value_lines))

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-03-02 10:24:56 +0000
+++ b/bzrlib/inventory.py	2009-03-05 14:42:38 +0000
@@ -1367,11 +1367,24 @@
 
 
 class CHKInventory(CommonInventory):
-    """A inventory persisted in a CHK store.
+    """An inventory persisted in a CHK store.
+
+    By design, a CHKInventory is immutable so many of the methods
+    supported by Inventory - add, rename, apply_delta, etc - are *not*
+    supported. To create a new CHKInventory, use create_by_apply_delta()
+    or from_inventory(), say.
+
+    Internally, a CHKInventory has one or two CHKMaps:
+
+    * id_to_entry - a map from (file_id,) => InventoryEntry as bytes
+    * parent_id_basename_to_file_id - a map from (parent_id, basename_utf8)
+        => file_id as bytes
+
+    The second map is optional and not present in early CHkRepository's.
 
     No caching is performed: every method call or item access will perform
-    requests to the storage layer. As such, keep references to objects you want
-    to reuse.
+    requests to the storage layer. As such, keep references to objects you
+    want to reuse.
     """
 
     def __init__(self, search_key_name):
@@ -1387,11 +1400,12 @@
 
         The BNF:
         ENTRY ::= FILE | DIR | SYMLINK | TREE
-        FILE ::= "file: " COMMON NULL SHA NULL SIZE NULL EXECUTABLE
+        FILE ::= "file: " COMMON SEP SHA SEP SIZE SEP EXECUTABLE
         DIR ::= "dir: " COMMON
-        SYMLINK ::= "symlink: " COMMON NULL TARGET_UTF8
+        SYMLINK ::= "symlink: " COMMON SEP TARGET_UTF8
         TREE ::= "tree: " COMMON REFERENCE_REVISION
-        COMMON ::= FILE_ID NULL PARENT_ID NULL NAME_UTF8 NULL REVISION
+        COMMON ::= FILE_ID SEP PARENT_ID SEP NAME_UTF8 SEP REVISION
+        SEP ::= "\n"
         """
         if entry.parent_id is not None:
             parent_str = entry.parent_id
@@ -1458,7 +1472,7 @@
         if self.root_id is not None:
             entries.next()
         inv = Inventory(self.root_id, self.revision_id)
-        for inv_entry in entries:
+        for path, inv_entry in entries:
             inv.add(inv_entry)
         return inv
 
@@ -1472,16 +1486,26 @@
         """
         result = CHKInventory(self._search_key_name)
         search_key_func = chk_map.search_key_registry.get(self._search_key_name)
+        self.id_to_entry._ensure_root()
+        maximum_size = self.id_to_entry._root_node.maximum_size
         result.revision_id = new_revision_id
         result.id_to_entry = chk_map.CHKMap(
             self.id_to_entry._store,
-            self.id_to_entry._root_node,
+            self.id_to_entry.key(),
             search_key_func=search_key_func)
+        result.id_to_entry._ensure_root()
+        result.id_to_entry._root_node.set_maximum_size(maximum_size)
         if self.parent_id_basename_to_file_id is not None:
             result.parent_id_basename_to_file_id = chk_map.CHKMap(
                 self.parent_id_basename_to_file_id._store,
-                self.parent_id_basename_to_file_id._root_node,
+                self.parent_id_basename_to_file_id.key(),
                 search_key_func=search_key_func)
+            result.parent_id_basename_to_file_id._ensure_root()
+            self.parent_id_basename_to_file_id._ensure_root()
+            result_p_id_root = self.parent_id_basename_to_file_id._root_node
+            p_id_root = self.parent_id_basename_to_file_id._root_node
+            result_p_id_root.set_maximum_size(p_id_root.maximum_size)
+            result_p_id_root._key_width = p_id_root._key_width
             parent_id_basename_delta = []
         else:
             result.parent_id_basename_to_file_id = None
@@ -1631,6 +1655,8 @@
 
     def has_id(self, file_id):
         # Perhaps have an explicit 'contains' method on CHKMap ?
+        if self._entry_cache.get(file_id, None) is not None:
+            return True
         return len(list(self.id_to_entry.iteritems([(file_id,)]))) == 1
 
     def is_root(self, file_id):



More information about the bazaar-commits mailing list