Rev 3473: Move _reannotate_annotated into AnnotationPolicy. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
John Arbash Meinel
john at arbash-meinel.com
Wed Jun 4 23:55:58 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
------------------------------------------------------------
revno: 3473
revision-id: john at arbash-meinel.com-20080604225545-f47gdy77gv92a95s
parent: john at arbash-meinel.com-20080604225134-h03xo9hmda5wzwtg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Wed 2008-06-04 17:55:45 -0500
message:
Move _reannotate_annotated into AnnotationPolicy.
modified:
bzrlib/annotate.py annotate.py-20050922133147-7c60541d2614f022
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2008-06-04 22:51:34 +0000
+++ b/bzrlib/annotate.py 2008-06-04 22:55:45 +0000
@@ -79,6 +79,55 @@
last_child_match = start_child + match_len
return lines
+ def _reannotate_annotated(self, right_parent_lines, plain_child_lines,
+ child_revision_id, annotated_lines,
+ heads_provider):
+ """Update the annotations for a node based on another parent.
+
+ :param right_parent_lines: A list of annotated lines for the right-hand
+ parent.
+ :param plain_child_lines: The unannotated new lines.
+ :param child_revision_id: The revision_id to attribute to lines which
+ are not present in either parent.
+ :param annotated_lines: A list of annotated lines. This should be the
+ annotation of plain_child_lines based on parents seen so far.
+ :param heads_provider: When parents disagree on the lineage of a line,
+ we need to check if one side supersedes the other.
+ """
+ if len(plain_child_lines) != len(annotated_lines):
+ raise AssertionError("mismatched plain_child_lines and annotated_lines")
+ # First compare the newly annotated lines with the right annotated lines.
+ # Lines which were not changed in left or right should match. This tends to
+ # be the bulk of the lines, and they will need no further processing.
+ lines = []
+ lines_extend = lines.extend
+ last_right_idx = 0 # The line just after the last match from the right side
+ last_left_idx = 0
+
+ matching_left_and_right = self._get_matching_blocks(right_parent_lines,
+ annotated_lines)
+ for right_idx, left_idx, match_len in matching_left_and_right:
+ # annotated lines from last_left_idx to left_idx did not match the lines from
+ # last_right_idx
+ # to right_idx, the raw lines should be compared to determine what annotations
+ # need to be updated
+ if last_right_idx == right_idx or last_left_idx == left_idx:
+ # One of the sides is empty, so this is a pure insertion
+ lines_extend(annotated_lines[last_left_idx:left_idx])
+ else:
+ # We need to see if any of the unannotated lines match
+ self.process_unmatched_lines(lines,
+ plain_child_lines, annotated_lines,
+ last_left_idx, left_idx,
+ right_parent_lines,
+ last_right_idx, right_idx,
+ heads_provider,
+ child_revision_id)
+ last_right_idx = right_idx + match_len
+ last_left_idx = left_idx + match_len
+ # If left and right agree on a range, just push that into the output
+ lines_extend(annotated_lines[left_idx:left_idx + match_len])
+ return lines
def process_unmatched_lines(self, output_lines, plain_child_lines,
annotated_child_lines, start_child, end_child,
@@ -307,7 +356,7 @@
elif len(parents_lines) == 2:
left = policy.reannotate_one(parents_lines[0], new_lines,
new_revision_id, _left_matching_blocks)
- lines = _reannotate_annotated(parents_lines[1], new_lines,
+ lines = policy._reannotate_annotated(parents_lines[1], new_lines,
new_revision_id, left,
heads_provider)
else:
@@ -357,53 +406,3 @@
old, new)
return matcher.get_matching_blocks()
-
-def _reannotate_annotated(right_parent_lines, new_lines, new_revision_id,
- annotated_lines, heads_provider):
- """Update the annotations for a node based on another parent.
-
- :param right_parent_lines: A list of annotated lines for the right-hand
- parent.
- :param new_lines: The unannotated new lines.
- :param new_revision_id: The revision_id to attribute to lines which are not
- present in either parent.
- :param annotated_lines: A list of annotated lines. This should be the
- annotation of new_lines based on parents seen so far.
- :param heads_provider: When parents disagree on the lineage of a line, we
- need to check if one side supersedes the other.
- """
- if len(new_lines) != len(annotated_lines):
- raise AssertionError("mismatched new_lines and annotated_lines")
- # First compare the newly annotated lines with the right annotated lines.
- # Lines which were not changed in left or right should match. This tends to
- # be the bulk of the lines, and they will need no further processing.
- lines = []
- lines_extend = lines.extend
- last_right_idx = 0 # The line just after the last match from the right side
- last_left_idx = 0
-
- policy = AnnotationPolicy()
- matching_left_and_right = _get_matching_blocks(right_parent_lines,
- annotated_lines)
- for right_idx, left_idx, match_len in matching_left_and_right:
- # annotated lines from last_left_idx to left_idx did not match the lines from
- # last_right_idx
- # to right_idx, the raw lines should be compared to determine what annotations
- # need to be updated
- if last_right_idx == right_idx or last_left_idx == left_idx:
- # One of the sides is empty, so this is a pure insertion
- lines_extend(annotated_lines[last_left_idx:left_idx])
- else:
- # We need to see if any of the unannotated lines match
- policy.process_unmatched_lines(lines,
- new_lines, annotated_lines,
- last_left_idx, left_idx,
- right_parent_lines,
- last_right_idx, right_idx,
- heads_provider,
- new_revision_id)
- last_right_idx = right_idx + match_len
- last_left_idx = left_idx + match_len
- # If left and right agree on a range, just push that into the output
- lines_extend(annotated_lines[left_idx:left_idx + match_len])
- return lines
More information about the bazaar-commits
mailing list