Rev 4470: Move more access patterns into helper functions. in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

John Arbash Meinel john at arbash-meinel.com
Thu Jun 18 21:07:07 BST 2009


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

------------------------------------------------------------
revno: 4470
revision-id: john at arbash-meinel.com-20090618200647-1j5kz9so3ma8b7o8
parent: john at arbash-meinel.com-20090618200356-aq8hb8fvb0iosu3r
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Thu 2009-06-18 15:06:47 -0500
message:
  Move more access patterns into helper functions.
-------------- next part --------------
=== modified file 'bzrlib/_annotator_py.py'
--- a/bzrlib/_annotator_py.py	2009-06-18 20:03:56 +0000
+++ b/bzrlib/_annotator_py.py	2009-06-18 20:06:47 +0000
@@ -58,6 +58,7 @@
             this_key = record.key
             lines = osutils.chunks_to_lines(record.get_bytes_as('chunked'))
             num_lines = len(lines)
+            self._text_cache[this_key] = lines
             yield this_key, lines, num_lines
 
     def _get_parent_annotations_and_matches(self, text, parent_key):
@@ -129,21 +130,32 @@
                     last_parent = par_ann
                     last_res = new_ann
 
+    def _init_annotations(self, key, num_lines):
+        """Build a new annotation list for this key.
+
+        :return: (this_annotation, annotations)
+            this_annotation: a tuple indicating this line was only introduced
+                             by revision key
+            annotations: A list of this_annotation keys
+        """
+        this_annotation = (key,)
+        # Note: annotations will be mutated by calls to _update_from*
+        annotations = [this_annotation] * num_lines
+        self._annotations_cache[key] = annotations
+        return this_annotation, annotations
+
     def annotate(self, key):
         """Return annotated fulltext for the given key."""
         keys = self._get_needed_texts(key)
         for text_key, text, num_lines in self._get_needed_texts(key):
-            self._text_cache[text_key] = text
-            this_annotation = (text_key,)
-            # Note: annotations will be mutated by calls to _update_from*
-            annotations = [this_annotation] * num_lines
-            self._annotations_cache[text_key] = annotations
+            (this_annotation,
+             annotations) = self._init_annotations(text_key, num_lines)
 
-            parents = self._parent_map[text_key]
-            if not parents:
+            parent_keys = self._parent_map[text_key]
+            if not parent_keys:
                 continue
-            self._update_from_one_parent(annotations, text, parents[0])
-            for parent in parents[1:]:
+            self._update_from_one_parent(annotations, text, parent_keys[0])
+            for parent in parent_keys[1:]:
                 self._update_from_other_parents(annotations, text,
                                                 this_annotation, parent)
         try:



More information about the bazaar-commits mailing list