Rev 3795: CombinedGraphIndex.iter_entries_prefix can now reload when needed. in http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/pack_retry_153786

John Arbash Meinel john at arbash-meinel.com
Thu Oct 23 21:51:23 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/pack_retry_153786

------------------------------------------------------------
revno: 3795
revision-id: john at arbash-meinel.com-20081023205058-z80mz4hp6o25v63w
parent: john at arbash-meinel.com-20081023203400-ftvlkbrx2zc8lww5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pack_retry_153786
timestamp: Thu 2008-10-23 15:50:58 -0500
message:
  CombinedGraphIndex.iter_entries_prefix can now reload when needed.
-------------- next part --------------
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2008-10-23 20:34:00 +0000
+++ b/bzrlib/index.py	2008-10-23 20:50:58 +0000
@@ -1233,12 +1233,17 @@
         if not keys:
             return
         seen_keys = set()
-        for index in self._indices:
-            for node in index.iter_entries_prefix(keys):
-                if node[1] in seen_keys:
-                    continue
-                seen_keys.add(node[1])
-                yield node
+        while True:
+            try:
+                for index in self._indices:
+                    for node in index.iter_entries_prefix(keys):
+                        if node[1] in seen_keys:
+                            continue
+                        seen_keys.add(node[1])
+                        yield node
+                return
+            except errors.NoSuchFile:
+                self._reload_or_raise()
 
     def key_count(self):
         """Return an estimate of the number of keys in this index.

=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py	2008-10-23 20:34:00 +0000
+++ b/bzrlib/tests/test_index.py	2008-10-23 20:50:58 +0000
@@ -1139,7 +1139,7 @@
         result = list(index.iter_entries([('1',), ('2',), ('3',)]))
         index3 = index._indices[0]
         # We had already yielded '1', so we just go on to the next, we should
-        # not yield '1' two times.
+        # not yield '1' twice.
         self.assertEqual([(index1, ('1',), ''), (index3, ('2',), '')],
                          result)
         self.assertEqual([1, 1, 0], reload_counter)
@@ -1170,7 +1170,7 @@
         result = list(index.iter_all_entries())
         index3 = index._indices[0]
         # We had already yielded '1', so we just go on to the next, we should
-        # not yield '1' two times.
+        # not yield '1' twice.
         self.assertEqual([(index1, ('1',), ''), (index3, ('2',), '')],
                          result)
         self.assertEqual([1, 1, 0], reload_counter)
@@ -1185,6 +1185,35 @@
                                     ['1', '2', '3'])
         self.assertListRaises(errors.NoSuchFile, index.iter_all_entries)
 
+    def test_iter_entries_prefix_reloads(self):
+        index, reload_counter = self.make_combined_index_with_missing()
+        result = list(index.iter_entries_prefix([('1',)]))
+        index3 = index._indices[0]
+        self.assertEqual([(index3, ('1',), '')], result)
+        self.assertEqual([1, 1, 0], reload_counter)
+
+    def test_iter_entries_prefix_reloads_midway(self):
+        index, reload_counter = self.make_combined_index_with_missing(['2'])
+        index1, index2 = index._indices
+        result = list(index.iter_entries_prefix([('1',)]))
+        index3 = index._indices[0]
+        # We had already yielded '1', so we just go on to the next, we should
+        # not yield '1' twice.
+        self.assertEqual([(index1, ('1',), '')], result)
+        self.assertEqual([1, 1, 0], reload_counter)
+
+    def test_iter_entries_prefix_no_reload(self):
+        index, reload_counter = self.make_combined_index_with_missing()
+        index._reload_func = None
+        self.assertListRaises(errors.NoSuchFile, index.iter_entries_prefix,
+                                                 [('1',)])
+
+    def test_iter_entries_prefix_reloads_and_fails(self):
+        index, reload_counter = self.make_combined_index_with_missing(
+                                    ['1', '2', '3'])
+        self.assertListRaises(errors.NoSuchFile, index.iter_entries_prefix,
+                                                 [('1',)])
+
 
 class TestInMemoryGraphIndex(TestCaseWithMemoryTransport):
 



More information about the bazaar-commits mailing list