Rev 3472: move in another function. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation

John Arbash Meinel john at arbash-meinel.com
Wed Jun 4 23:51:48 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation

------------------------------------------------------------
revno: 3472
revision-id: john at arbash-meinel.com-20080604225134-h03xo9hmda5wzwtg
parent: john at arbash-meinel.com-20080604223747-vf0mbkj5goxkyc3w
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Wed 2008-06-04 17:51:34 -0500
message:
  move in another function.
modified:
  bzrlib/annotate.py             annotate.py-20050922133147-7c60541d2614f022
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py	2008-06-04 22:37:47 +0000
+++ b/bzrlib/annotate.py	2008-06-04 22:51:34 +0000
@@ -51,6 +51,35 @@
         matcher = self._sequence_matcher(None, old, new)
         return matcher.get_matching_blocks()
 
+    def reannotate_one(self, annotated_parent_lines, plain_child_lines,
+                       child_revision_id, matching_blocks=None):
+        """Given an annotated parent, annotate the child.
+
+        :param annotated_parent_lines: The base lines we will use for
+            annotating
+        :param plain_child_lines: A list of strings to be annotated
+        :param child_revision_id: The revision id to assign to lines that are
+            new in the child
+        :param matching_blocks: If None, they will be recomputed. Otherwise,
+            we assume that the caller already knows which lines should match.
+            Should be a list of (start_parent, start_child, match_len) tuples.
+        :return: A list of annotated lines.
+        """
+        last_child_match = 0
+        if matching_blocks is None:
+            plain_parent_lines = [l for r, l in annotated_parent_lines]
+            matching_blocks = self._get_matching_blocks(plain_parent_lines,
+                                                        plain_child_lines)
+        lines = []
+        for start_parent, start_child, match_len in matching_blocks:
+            # add any lines from the child that didn't match
+            lines.extend((child_revision_id, l) for l in
+                          plain_child_lines[last_child_match:start_child])
+            lines.extend(annotated_parent_lines[start_parent:start_parent + match_len])
+            last_child_match = start_child + match_len
+        return lines
+
+
     def process_unmatched_lines(self, output_lines, plain_child_lines,
                                 annotated_child_lines, start_child, end_child,
                                 annotated_right_lines, start_right, end_right,
@@ -269,21 +298,25 @@
         If None, then any ancestry disputes will be resolved with
         new_revision_id
     """
+    policy = AnnotationPolicy()
     if len(parents_lines) == 0:
         lines = [(new_revision_id, line) for line in new_lines]
     elif len(parents_lines) == 1:
-        lines = _reannotate(parents_lines[0], new_lines, new_revision_id,
-                            _left_matching_blocks)
+        lines = policy.reannotate_one(parents_lines[0], new_lines,
+                    new_revision_id, _left_matching_blocks)
     elif len(parents_lines) == 2:
-        left = _reannotate(parents_lines[0], new_lines, new_revision_id,
-                           _left_matching_blocks)
+        left = policy.reannotate_one(parents_lines[0], new_lines,
+                    new_revision_id, _left_matching_blocks)
         lines = _reannotate_annotated(parents_lines[1], new_lines,
                                       new_revision_id, left,
                                       heads_provider)
     else:
-        reannotations = [_reannotate(parents_lines[0], new_lines,
+        # Annotate the child lines versus each parent, and then match up the
+        # lines one-by-one
+        reannotations = [policy.reannotate_one(parents_lines[0], new_lines,
                                      new_revision_id, _left_matching_blocks)]
-        reannotations.extend(_reannotate(p, new_lines, new_revision_id)
+        reannotations.extend(policy.reannotate_one(p, new_lines,
+                                                   new_revision_id)
                              for p in parents_lines[1:])
         lines = []
         for annos in zip(*reannotations):



More information about the bazaar-commits mailing list