Rev 3794: CombinedGraphIndex.iter_all_entries() 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:34:52 BST 2008


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

------------------------------------------------------------
revno: 3794
revision-id: john at arbash-meinel.com-20081023203400-ftvlkbrx2zc8lww5
parent: john at arbash-meinel.com-20081023202849-2k0p95mvwrhcjze9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pack_retry_153786
timestamp: Thu 2008-10-23 15:34:00 -0500
message:
  CombinedGraphIndex.iter_all_entries() can now reload when needed.
-------------- next part --------------
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2008-10-23 20:28:49 +0000
+++ b/bzrlib/index.py	2008-10-23 20:34:00 +0000
@@ -1174,11 +1174,16 @@
             the most efficient order for the index.
         """
         seen_keys = set()
-        for index in self._indices:
-            for node in index.iter_all_entries():
-                if node[1] not in seen_keys:
-                    yield node
-                    seen_keys.add(node[1])
+        while True:
+            try:
+                for index in self._indices:
+                    for node in index.iter_all_entries():
+                        if node[1] not in seen_keys:
+                            yield node
+                            seen_keys.add(node[1])
+                return
+            except errors.NoSuchFile:
+                self._reload_or_raise()
 
     def iter_entries(self, keys):
         """Iterate over keys within the index.

=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py	2008-10-23 20:28:49 +0000
+++ b/bzrlib/tests/test_index.py	2008-10-23 20:34:00 +0000
@@ -1138,7 +1138,8 @@
         index1, index2 = index._indices
         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 had already yielded '1', so we just go on to the next, we should
+        # not yield '1' two times.
         self.assertEqual([(index1, ('1',), ''), (index3, ('2',), '')],
                          result)
         self.assertEqual([1, 1, 0], reload_counter)
@@ -1155,6 +1156,34 @@
         self.assertListRaises(errors.NoSuchFile, index.iter_entries, [('3',)])
         self.assertEqual([2, 1, 1], reload_counter)
 
+    def test_iter_all_entries_reloads(self):
+        index, reload_counter = self.make_combined_index_with_missing()
+        result = list(index.iter_all_entries())
+        index3 = index._indices[0]
+        self.assertEqual([(index3, ('1',), ''), (index3, ('2',), '')],
+                         result)
+        self.assertEqual([1, 1, 0], reload_counter)
+
+    def test_iter_all_entries_reloads_midway(self):
+        index, reload_counter = self.make_combined_index_with_missing(['2'])
+        index1, index2 = index._indices
+        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.
+        self.assertEqual([(index1, ('1',), ''), (index3, ('2',), '')],
+                         result)
+        self.assertEqual([1, 1, 0], reload_counter)
+
+    def test_iter_all_entries_no_reload(self):
+        index, reload_counter = self.make_combined_index_with_missing()
+        index._reload_func = None
+        self.assertListRaises(errors.NoSuchFile, index.iter_all_entries)
+
+    def test_iter_all_entries_reloads_and_fails(self):
+        index, reload_counter = self.make_combined_index_with_missing(
+                                    ['1', '2', '3'])
+        self.assertListRaises(errors.NoSuchFile, index.iter_all_entries)
 
 
 class TestInMemoryGraphIndex(TestCaseWithMemoryTransport):



More information about the bazaar-commits mailing list