Rev 4045: Turn _split_by_prefix into a classmethod, and add direct tests. in lp:///~jameinel/bzr/sort_knit_fetch

John Arbash Meinel john at arbash-meinel.com
Wed Feb 25 20:23:11 GMT 2009


At lp:///~jameinel/bzr/sort_knit_fetch

------------------------------------------------------------
revno: 4045
revision-id: john at arbash-meinel.com-20090225202304-j52lrdrx8aw101uh
parent: john at arbash-meinel.com-20090225201213-fwl3dlpkraaogv7l
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: sort_knit_fetch
timestamp: Wed 2009-02-25 14:23:04 -0600
message:
  Turn _split_by_prefix into a classmethod, and add direct tests.
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2009-02-25 20:12:13 +0000
+++ b/bzrlib/knit.py	2009-02-25 20:23:04 +0000
@@ -818,7 +818,6 @@
         as returned by _get_components_positions)
     :return: Number of bytes to build those keys
     """
-    index_memos = set()
     all_build_index_memos = {}
     build_keys = keys
     while build_keys:
@@ -1223,7 +1222,8 @@
             except errors.RetryWithNewPacks, e:
                 self._access.reload_or_raise(e)
 
-    def _split_by_prefix(self, keys):
+    @classmethod
+    def _split_by_prefix(cls, keys):
         """For the given keys, split them up based on their prefix.
 
         To keep memory pressure somewhat under control, split the
@@ -1232,9 +1232,9 @@
         This should be revisited if _get_content_maps() can ever cross
         file-id boundaries.
 
-        Note that the keys are generally kept in the same order, so if you
-        present them in a sorted order, the sorting will generally be
-        preserved.
+        The keys for a given file_id are kept in the same relative order.
+        Ordering between file_ids is not, though prefix_order will return the
+        order that the key was first seen.
 
         :param keys: An iterable of key tuples
         :return: (split_map, prefix_order)

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2009-02-25 20:12:13 +0000
+++ b/bzrlib/tests/test_knit.py	2009-02-25 20:23:04 +0000
@@ -1887,6 +1887,42 @@
         self.assertEqual([], self.caught_entries)
 
 
+class TestKnitVersionedFiles(KnitTests):
+
+    def assertSplitByPrefix(self, expected_map, expected_prefix_order,
+                            keys):
+        split, prefix_order = KnitVersionedFiles._split_by_prefix(keys)
+        self.assertEqual(expected_map, split)
+        self.assertEqual(expected_prefix_order, prefix_order)
+
+    def test__split_by_prefix(self):
+        self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
+                                  'g': [('g', 'b'), ('g', 'a')],
+                                 }, ['f', 'g'],
+                                 [('f', 'a'), ('g', 'b'),
+                                  ('g', 'a'), ('f', 'b')])
+
+        self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
+                                  'g': [('g', 'b'), ('g', 'a')],
+                                 }, ['f', 'g'],
+                                 [('f', 'a'), ('f', 'b'),
+                                  ('g', 'b'), ('g', 'a')])
+
+        self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
+                                  'g': [('g', 'b'), ('g', 'a')],
+                                 }, ['f', 'g'],
+                                 [('f', 'a'), ('f', 'b'),
+                                  ('g', 'b'), ('g', 'a')])
+
+        self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
+                                  'g': [('g', 'b'), ('g', 'a')],
+                                  '': [('a',), ('b',)]
+                                 }, ['f', 'g', ''],
+                                 [('f', 'a'), ('g', 'b'),
+                                  ('a',), ('b',),
+                                  ('g', 'a'), ('f', 'b')])
+
+
 class TestStacking(KnitTests):
 
     def get_basis_and_test_knit(self):



More information about the bazaar-commits mailing list