Rev 4798: Test that we parse the mini-index entries properly. in http://bazaar.launchpad.net/~jameinel/bzr/chk-index

John Arbash Meinel john at arbash-meinel.com
Wed Oct 28 18:24:28 GMT 2009


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

------------------------------------------------------------
revno: 4798
revision-id: john at arbash-meinel.com-20091028182419-isq5q9qja7jeifmo
parent: john at arbash-meinel.com-20091028181549-7i661tkwez8sbp52
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: chk-index
timestamp: Wed 2009-10-28 13:24:19 -0500
message:
  Test that we parse the mini-index entries properly.
-------------- next part --------------
=== modified file 'bzrlib/chk_index.py'
--- a/bzrlib/chk_index.py	2009-10-28 18:07:25 +0000
+++ b/bzrlib/chk_index.py	2009-10-28 18:24:19 +0000
@@ -467,6 +467,10 @@
         #       start-of-records header here?
         sorted_groups = self._sort_groups()
         pack = header.group_coder.pack
+        # Note: When unpacking, we decided to unpack as a giant group, and then
+        #       parse out the tuple. We may want to do the same thing here for
+        #       packing. It would give us a single byte string, rather than an
+        #       array of byte strings.
         bytes = [pack(*group_key) for group_key in sorted_groups]
         # Note: In testing with Launchpad, the fixed-width for groups and
         #       lengths was not a big win. Namely, there was a lot of wasted
@@ -634,11 +638,10 @@
             # (offset, loaded?)
             self._mini_index = [stuple(self._header.entry_offset, False)]
             return
-        bork
         self._header._build_mini_index_coder()
         start = self._header.mini_index_offset
         end = self._header.group_index_offset
-        format = self._header.group_coder.format[1:]
+        format = self._header.mini_index_coder.format[1:]
         format = '>' + (format * self._header.num_mini_index_entries)
         as_ints = struct.unpack(format, bytes[start:end])
         self._mini_index = [stuple(i, False) for i in as_ints]

=== modified file 'bzrlib/tests/test_chk_index.py'
--- a/bzrlib/tests/test_chk_index.py	2009-10-28 18:15:49 +0000
+++ b/bzrlib/tests/test_chk_index.py	2009-10-28 18:24:19 +0000
@@ -100,7 +100,6 @@
 
 class TestCHKIndexBuilder(tests.TestCase):
 
-
     def test__ensure_group(self):
         builder = chk_index.CHKIndexBuilder()
         self.assertEqual({(0, 0): 0}, builder._groups)
@@ -774,3 +773,19 @@
         # TODO: the value of _mini_index when there isn't an index present is
         #       currently up for grabs.
         self.assertEqual([(126, False)], index._mini_index)
+
+    def test__ensure_header_small(self):
+        nodes = make_chk_nodes(400, 20)
+        index = self.make_index(nodes)
+        index._ensure_header()
+        self.assertIsNot(None, index._header)
+        self.assertEqual(400, index._header.num_entries)
+        self.assertEqual(21, index._header.num_groups)
+        self.assertIsNot(None, index._groups)
+
+        groups = sorted(set([(node[1], node[2]) for node in nodes]))
+        groups.insert(0, (0, 0))
+        self.assertEqual(groups, index._groups)
+        mini_index = [(x, False) for x in [278, 734, 1382, 1958, 2582, 3038,
+            3854, 4454, 5198, 5798, 6398, 7190, 7814, 8294, 8918, 9398]]
+        self.assertEqual(mini_index, index._mini_index)



More information about the bazaar-commits mailing list