Rev 4484: add a bit more work to be able to process 'pending_annotations'. in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

John Arbash Meinel john at arbash-meinel.com
Tue Jun 23 06:14:33 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

------------------------------------------------------------
revno: 4484
revision-id: john at arbash-meinel.com-20090623051346-fnkyjowhwxodurqr
parent: john at arbash-meinel.com-20090620052814-wzxvfjdkxr7cn939
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Tue 2009-06-23 00:13:46 -0500
message:
  add a bit more work to be able to process 'pending_annotations'.
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2009-06-20 05:28:14 +0000
+++ b/bzrlib/knit.py	2009-06-23 05:13:46 +0000
@@ -3322,6 +3322,9 @@
         # Delta records that need their compression parent before they can be
         # expanded
         self._pending_deltas = {}
+        # Fulltext records that are waiting for their parents fulltexts before
+        # they can be yielded for annotation
+        self._pending_annotation = {}
 
         self._all_build_details = {}
 
@@ -3409,7 +3412,8 @@
             #       can set 'copy_base_content = False' and remove base_content
             #       from the cache (to be inserted as the new content)
             content, _ = self._vf._factory.parse_record(
-                key, record, record_details, None, copy_base_content=True)
+                key, record, record_details, base_content,
+                copy_base_content=True)
         else:
             # Fulltext record
             content, _ = self._vf._factory.parse_record(
@@ -3435,6 +3439,39 @@
         #             self._content_objects[child_key] = child_content
         #             to_process.append((child_key, child_parent_keys, child_content))
 
+    def _process_pending(self, key):
+        """The content for 'key' was just processed.
+
+        Determine if there is any more pending work to be processed.
+        """
+        if key not in self._pending_deltas:
+            return []
+        compression_parent = key
+        children = self._pending_deltas.pop(key)
+        to_return = []
+        for key, parent_keys, record, record_details in children:
+            lines = self._expand_record(key, parent_keys, compression_parent,
+                                        record, record_details)
+            assert lines is not None
+            if self._check_ready_for_annotations(key, parent_keys):
+                to_return.append(key)
+
+    def _check_ready_for_annotations(self, key, parent_keys):
+        """return true if this text is ready to be yielded.
+
+        Otherwise, this will return False, and queue the text into
+        self._pending_annotation
+        """
+        for parent_key in parent_keys:
+            if parent_key not in self._annotations_cache:
+                # still waiting on at least one parent text, so queue it up
+                # Note that if there are multiple parents, we need to wait
+                # for all of them.
+                self._pending_annotation.setdefault(parent_key,
+                    []).append((key, parent_keys))
+                return False
+        return True
+
     def _extract_texts(self, records):
         """Extract the various texts needed based on records"""
         # We iterate in the order read, rather than a strict order requested
@@ -3465,9 +3502,6 @@
         # that we know when we can re-use the content lines, and the annotation
         # code can know when it can stop caching fulltexts, as well.
 
-        # Children that we want to annotate as soon as we get the parent text
-        # Map from parent_key => [child_key]
-        pending_annotation = {}
         # Children that are missing their compression parent
         pending_deltas = {}
         for (key, record, digest) in self._vf._read_records_iter(records):
@@ -3482,16 +3516,8 @@
                 continue
             # At this point, we may be able to yield this content, if all
             # parents are also finished
-            yield_this_text = True
-            for parent_key in parent_keys:
-                if parent_key not in self._annotations_cache:
-                    # still waiting on at least one parent text, so queue it up
-                    # Note that if there are multiple parents, we need to wait
-                    # for all of them.
-                    pending_annotation.setdefault(parent_key,
-                        []).append((key, parent_keys, content))
-                    yield_this_text = False
-                    break
+            yield_this_text = self._check_ready_for_annotations(key,
+                                                                parent_keys)
             if yield_this_text:
                 # All parents present
                 yield key, lines, len(lines)

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2009-06-20 05:11:51 +0000
+++ b/bzrlib/tests/test_knit.py	2009-06-23 05:13:46 +0000
@@ -1332,7 +1332,7 @@
         self.assertEqual(res, content_obj.text())
         self.assertEqual(res, ann._text_cache[rev_key])
 
-    def test__expand_delta_no_parent(self):
+    def test__expand_delta_comp_parent_not_available(self):
         # Parent isn't available yet, so we return nothing, but queue up this
         # node for later processing
         ann = self.make_annotator()
@@ -1348,6 +1348,32 @@
         self.assertEqual(1, len(pending))
         self.assertEqual((rev_key, (parent_key,), record, details), pending[0])
 
+    def test__expand_delta_right_parent_not_available(self):
+        ann = self.make_annotator()
+        rev_key = ('rev-id',)
+        p1_key = ('p1-id',)
+        p2_key = ('p2-id',)
+        record = ['0,1,1\n', 'new-line\n']
+        details = ('line-delta', False)
+        p1_record = ['line1\n', 'line2\n']
+        res = ann._expand_record(rev_key, (p1_key,p2_key), p1_key,
+                                 record, details)
+        self.assertEqual(None, res)
+        # self.assertTrue(p1_key in ann._pending_deltas)
+        self.assertEqual({}, ann._pending_annotation)
+        # Now insert p1, and we should be able to expand the delta
+        res = ann._expand_record(p1_key, (), None, p1_record,
+                                 ('fulltext', False))
+        self.assertEqual(p1_record, res)
+        ann._annotations_cache[p1_key] = [(p1_key,)]*2
+        res = ann._process_pending(p1_key)
+        self.assertFalse(p1_key in ann._pending_deltas)
+        self.assertTrue(p2_key in ann._pending_annotation)
+        self.assertEqual({p2_key: [(rev_key, (p1_key, p2_key))]},
+                         ann._pending_annotation)
+        # Now fill in parent 2, and pending annotation should be satisfied
+        res = ann._expand_record(p2_key, (), None, [], ('fulltext', False))
+
     def test_record_delta_removes_basis(self):
         ann = self.make_annotator()
         ann._expand_record(('parent-id',), (), None,



More information about the bazaar-commits mailing list