Rev 2635: Various index tweaks and test clarity from John's review. in http://people.ubuntu.com/~robertc/baz2.0/index

Robert Collins robertc at robertcollins.net
Sun Jul 15 05:45:21 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/index

------------------------------------------------------------
revno: 2635
revision-id: robertc at robertcollins.net-20070715044519-140kzz00uzldgt7z
parent: robertc at robertcollins.net-20070715044034-121yu86vvyet4akv
committer: Robert Collins <robertc at robertcollins.net>
branch nick: index
timestamp: Sun 2007-07-15 14:45:19 +1000
message:
  Various index tweaks and test clarity from John's review.
modified:
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
  bzrlib/tests/test_index.py     test_index.py-20070712131115-lolkarso50vjr64s-2
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2007-07-15 04:40:34 +0000
+++ b/bzrlib/index.py	2007-07-15 04:45:19 +0000
@@ -212,7 +212,8 @@
             if line == '\n':
                 trailers += 1
                 continue
-            key, absent, references, value = line[:-1].split('\0')
+            key, absent, references, value = line.split('\0')
+            value = value[:-1] # remove the newline
             ref_lists = []
             for ref_string in references.split('\t'):
                 ref_lists.append(tuple([
@@ -221,7 +222,7 @@
             ref_lists = tuple(ref_lists)
             self.keys_by_offset[pos] = (key, absent, ref_lists, value)
             pos += len(line)
-        for key, absent, references, value in self.keys_by_offset.values():
+        for key, absent, references, value in self.keys_by_offset.itervalues():
             if absent:
                 continue
             # resolve references:

=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py	2007-07-15 04:30:29 +0000
+++ b/bzrlib/tests/test_index.py	2007-07-15 04:45:19 +0000
@@ -47,7 +47,7 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
-            "akey\0\0\0data\n\n", contents)
+            "akey\x00\x00\x00data\n\n", contents)
 
     def test_add_node_empty_value(self):
         builder = GraphIndexBuilder()
@@ -55,7 +55,7 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
-            "akey\0\0\0\n\n", contents)
+            "akey\x00\x00\x00\n\n", contents)
 
     def test_build_index_two_nodes_sorted(self):
         # the highest sorted node comes first.
@@ -69,9 +69,9 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=0\n"
-            "2000\0\0\0data\n"
-            "2001\0\0\0data\n"
-            "2002\0\0\0data\n"
+            "2000\x00\x00\x00data\n"
+            "2001\x00\x00\x00data\n"
+            "2002\x00\x00\x00data\n"
             "\n", contents)
 
     def test_build_index_reference_lists_are_included_one(self):
@@ -80,7 +80,7 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
-            "key\0\0\0data\n"
+            "key\x00\x00\x00data\n"
             "\n", contents)
 
     def test_build_index_reference_lists_are_included_two(self):
@@ -89,7 +89,7 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n"
-            "key\0\0\t\0data\n"
+            "key\x00\x00\t\x00data\n"
             "\n", contents)
 
     def test_node_references_are_byte_offsets(self):
@@ -111,9 +111,9 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
-            "key\0\x0054\r71\0data\n"
-            "reference\0\0\0data\n"
-            "reference2\0\0\0data\n"
+            "key\x00\x0054\r71\x00data\n"
+            "reference\x00\x00\x00data\n"
+            "reference2\x00\x00\x00data\n"
             "\n", contents)
 
     def test_multiple_reference_lists_are_tab_delimited(self):
@@ -123,8 +123,8 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=2\n"
-            "keference\0\0\t\0data\n"
-            "rey\0\x0038\t38\0data\n"
+            "keference\x00\x00\t\x00data\n"
+            "rey\x00\x0038\t38\x00data\n"
             "\n", contents)
 
     def test_add_node_referencing_missing_key_makes_absent(self):
@@ -133,9 +133,9 @@
         stream = builder.finish()
         contents = stream.read()
         self.assertEqual("Bazaar Graph Index 1\nnode_ref_lists=1\n"
-            "aeference2\0a\0\0\n"
-            "beference\0a\0\0\n"
-            "rey\0\x0053\r38\0data\n"
+            "aeference2\x00a\x00\x00\n"
+            "beference\x00a\x00\x00\n"
+            "rey\x00\x0053\r38\x00data\n"
             "\n", contents)
 
     def test_node_references_three_digits(self):
@@ -184,7 +184,7 @@
         self.assertRaises(errors.BadIndexValue, builder.add_node, 'akey',
             (), 'data\naa')
         self.assertRaises(errors.BadIndexValue, builder.add_node, 'akey',
-            (), 'data\0aa')
+            (), 'data\x00aa')
 
     def test_add_node_bad_mismatched_ref_lists_length(self):
         builder = GraphIndexBuilder()



More information about the bazaar-commits mailing list