Rev 3818: Fix all the various places that were assuming how the bytes were laid out. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/hack

John Arbash Meinel john at arbash-meinel.com
Tue Dec 23 21:52:06 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/hack

------------------------------------------------------------
revno: 3818
revision-id: john at arbash-meinel.com-20081223215151-ap2f6vkfrnwlncz8
parent: john at arbash-meinel.com-20081223213719-3004u6x38jnh436l
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hack
timestamp: Tue 2008-12-23 15:51:51 -0600
message:
  Fix all the various places that were assuming how the bytes were laid out.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2008-12-23 21:37:19 +0000
+++ b/bzrlib/chk_map.py	2008-12-23 21:51:51 +0000
@@ -500,16 +500,18 @@
         """
         if self._common_serialised_prefix is None:
             bytes_for_items = 0
+            prefix_len = 0
         else:
             # We will store a single string with the common prefix
             # And then that common prefix will not be stored in any of the
             # entry lines
             prefix_len = len(self._common_serialised_prefix)
-            bytes_for_items = (self._raw_size - (prefix_len * (self._len - 1)))
-        return (13 # bytes overhead for the header and separators
-            + len(str(self._maximum_size))
-            + len(str(self._key_width))
-            + len(str(self._len))
+            bytes_for_items = (self._raw_size - (prefix_len * self._len))
+        return (9 # 'chkleaf:\n'
+            + len(str(self._maximum_size)) + 1
+            + len(str(self._key_width)) + 1
+            + len(str(self._len)) + 1
+            + prefix_len + 1
             + bytes_for_items)
 
     @classmethod
@@ -530,7 +532,8 @@
         length = int(lines[3])
         pos = 5
         prefix = lines[4]
-        assert prefix.pop() == '\n' # Remove the trailing newline
+        assert prefix[-1] == '\n'
+        prefix = prefix[:-1] # Remove the trailing newline
         while pos < len(lines):
             elements = (prefix + lines[pos]).split('\x00')
             assert len(elements) == width + 1
@@ -547,13 +550,13 @@
             raise AssertionError("item count mismatch")
         result._items = items
         result._len = length
-        assert length == len(lines) - 5
+        # assert length == len(lines) - 5
         result._maximum_size = maximum_size
         result._key = key
         result._orig_key = key
         result._key_width = width
         result._raw_size = (sum(map(len, lines[5:])) # the length of the suffix
-            + (length)*(len(prefix)+1)) # prefix + '\n'
+            + (length)*(len(prefix))) # prefix
         result._compute_lookup_prefix()
         result._compute_serialised_prefix()
         if len(bytes) != result._current_size():
@@ -588,7 +591,9 @@
     def _key_value_len(self, key, value):
         # TODO: Should probably be done without actually joining the key, but
         #       then that can be done via the C extension
-        return 2 + len(self._serialise_key(key)) + len(value)
+        return (len(self._serialise_key(key)) + 1
+                + len(str(value.count('\n'))) + 1
+                + len(value) + 1)
 
     def _map_no_split(self, key, value):
         """Map a key to a value.



More information about the bazaar-commits mailing list