Rev 3475: it seems to all be AnnotationPolicy now. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
John Arbash Meinel
john at arbash-meinel.com
Thu Jun 5 02:31:46 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
------------------------------------------------------------
revno: 3475
revision-id: john at arbash-meinel.com-20080604231902-2i8nzp5p3jd79jpw
parent: john at arbash-meinel.com-20080604225908-cbnxepcjoqcsy65n
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Wed 2008-06-04 18:19:02 -0500
message:
it seems to all be AnnotationPolicy now.
modified:
bzrlib/annotate.py annotate.py-20050922133147-7c60541d2614f022
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2008-06-04 22:59:08 +0000
+++ b/bzrlib/annotate.py 2008-06-04 23:19:02 +0000
@@ -51,7 +51,60 @@
matcher = self._sequence_matcher(None, old, new)
return matcher.get_matching_blocks()
- def reannotate_one(self, annotated_parent_lines, plain_child_lines,
+ def reannotate(self, parents_lines, new_lines, new_revision_id,
+ _left_matching_blocks=None, heads_provider=None):
+ """Annotate the lines given parent annotations.
+
+ :param parents_lines: List of annotated lines for all parents
+ :param new_lines: The un-annotated new lines
+ :param new_revision_id: The revision-id to associate with new lines
+ (will often be CURRENT_REVISION)
+ :param left_matching_blocks: a hint about which areas are common
+ between the text and its left-hand-parent. The format is
+ the SequenceMatcher.get_matching_blocks format
+ (start_left, start_right, length_of_match).
+ :param heads_provider: An object which provids a .heads() call to
+ resolve if any revision ids are children of others.
+ If None, then any ancestry disputes will be resolved with
+ new_revision_id
+ :return: A list of annotated lines.
+ """
+ if len(parents_lines) == 0:
+ lines = [(new_revision_id, line) for line in new_lines]
+ elif len(parents_lines) == 1:
+ lines = self._reannotate_one(parents_lines[0], new_lines,
+ new_revision_id, _left_matching_blocks)
+ elif len(parents_lines) == 2:
+ left = self._reannotate_one(parents_lines[0], new_lines,
+ new_revision_id, _left_matching_blocks)
+ lines = self._reannotate_annotated(parents_lines[1], new_lines,
+ new_revision_id, left,
+ heads_provider)
+ else:
+ # Annotate the child lines versus each parent, and then match up the
+ # lines one-by-one
+ reannotations = [self._reannotate_one(parents_lines[0], new_lines,
+ new_revision_id, _left_matching_blocks)]
+ reannotations.extend(self._reannotate_one(p, new_lines,
+ new_revision_id)
+ for p in parents_lines[1:])
+ lines = []
+ for annos in zip(*reannotations):
+ origins = set(a for a, l in annos)
+ if len(origins) == 1:
+ # All the parents agree, so just return the first one
+ lines.append(annos[0])
+ else:
+ line = annos[0][1]
+ if len(origins) == 2 and new_revision_id in origins:
+ origins.remove(new_revision_id)
+ if len(origins) == 1:
+ lines.append((origins.pop(), line))
+ else:
+ lines.append((new_revision_id, line))
+ return lines
+
+ def _reannotate_one(self, annotated_parent_lines, plain_child_lines,
child_revision_id, matching_blocks=None):
"""Given an annotated parent, annotate the child.
@@ -116,14 +169,14 @@
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)
+ 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
@@ -131,7 +184,7 @@
lines_extend(annotated_lines[left_idx:left_idx + match_len])
return lines
- def process_unmatched_lines(self, output_lines, plain_child_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,
heads_provider, revision_id):
@@ -350,40 +403,9 @@
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 = policy.reannotate_one(parents_lines[0], new_lines,
- new_revision_id, _left_matching_blocks)
- elif len(parents_lines) == 2:
- left = policy.reannotate_one(parents_lines[0], new_lines,
- new_revision_id, _left_matching_blocks)
- lines = policy._reannotate_annotated(parents_lines[1], new_lines,
- new_revision_id, left,
- heads_provider)
- else:
- # 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(policy.reannotate_one(p, new_lines,
- new_revision_id)
- for p in parents_lines[1:])
- lines = []
- for annos in zip(*reannotations):
- origins = set(a for a, l in annos)
- if len(origins) == 1:
- # All the parents agree, so just return the first one
- lines.append(annos[0])
- else:
- line = annos[0][1]
- if len(origins) == 2 and new_revision_id in origins:
- origins.remove(new_revision_id)
- if len(origins) == 1:
- lines.append((origins.pop(), line))
- else:
- lines.append((new_revision_id, line))
- return lines
+ return policy.reannotate(parents_lines, new_lines, new_revision_id,
+ _left_matching_blocks=_left_matching_blocks,
+ heads_provider=heads_provider)
def _reannotate(parent_lines, new_lines, new_revision_id,
More information about the bazaar-commits
mailing list