Rev 3476: Move the heads provider to be part of the class, rather than a parameter. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
John Arbash Meinel
john at arbash-meinel.com
Thu Jun 5 02:32:42 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation
------------------------------------------------------------
revno: 3476
revision-id: john at arbash-meinel.com-20080605013229-m3r1oknwt8d3lcjr
parent: john at arbash-meinel.com-20080604231902-2i8nzp5p3jd79jpw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Wed 2008-06-04 20:32:29 -0500
message:
Move the heads provider to be part of the class, rather than a parameter.
modified:
bzrlib/annotate.py annotate.py-20050922133147-7c60541d2614f022
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py 2008-06-04 23:19:02 +0000
+++ b/bzrlib/annotate.py 2008-06-05 01:32:29 +0000
@@ -52,7 +52,7 @@
return matcher.get_matching_blocks()
def reannotate(self, parents_lines, new_lines, new_revision_id,
- _left_matching_blocks=None, heads_provider=None):
+ _left_matching_blocks=None):
"""Annotate the lines given parent annotations.
:param parents_lines: List of annotated lines for all parents
@@ -63,10 +63,6 @@
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:
@@ -78,8 +74,7 @@
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)
+ new_revision_id, left)
else:
# Annotate the child lines versus each parent, and then match up the
# lines one-by-one
@@ -133,8 +128,7 @@
return lines
def _reannotate_annotated(self, right_parent_lines, plain_child_lines,
- child_revision_id, annotated_lines,
- heads_provider):
+ child_revision_id, annotated_lines):
"""Update the annotations for a node based on another parent.
:param right_parent_lines: A list of annotated lines for the right-hand
@@ -144,8 +138,6 @@
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")
@@ -175,7 +167,6 @@
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
@@ -187,7 +178,7 @@
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):
+ revision_id):
"""Find lines in plain right_lines that match plain_child_lines
:param output_lines: Append final annotated lines to this list
@@ -204,8 +195,6 @@
match
:param end_right: Last position in annotated_right_lines to search for
a match
- :param heads_provider: When parents disagree on the lineage of a line,
- we need to check if one side supersedes the other
:param revision_id: The label to give if a line should be labeled 'tip'
"""
output_extend = output_lines.extend
@@ -219,8 +208,6 @@
last_child_idx = 0
- self._heads_provider = heads_provider
-
for right_idx, child_idx, match_len in match_blocks:
# All the lines that don't match are just passed along
if child_idx > last_child_idx:
@@ -247,6 +234,43 @@
Resolve this somehow.
"""
+ raise NotImplementedError(self._resolve_ambiguous)
+ if self._heads_provider is not None:
+ heads = self._heads_provider.heads((left[0], right[0]))
+ if len(heads) == 1:
+ return (iter(heads).next(), left[1])
+ else:
+ # Both claim different origins
+ # We know that revision_id is the head for
+ # left and right, so cache it
+ self._heads_provider.cache(
+ (revision_id, left[0]),
+ (revision_id,))
+ self._heads_provider.cache(
+ (revision_id, right[0]),
+ (revision_id,))
+ return (revision_id, left[1])
+ # Without a heads provider, we just always pick 'tip'
+ return (revision_id, left[1])
+
+
+class HeadsAnnotationPolicy(AnnotationPolicy):
+ """An annotation policy that uses a heads provider."""
+
+ def __init__(self, heads_provider):
+ """Create a new HeadsAnnotationPolicy.
+
+ :param heads_provider: An object which provids a .heads() call to
+ resolve if any revision ids are children of others.
+ """
+ super(HeadsAnnotationPolicy, self).__init__()
+ self._heads_provider = heads_provider
+
+ def _resolve_ambiguous(self, revision_id, left, right):
+ """We have an ambiguous line between two texts.
+
+ Resolve this somehow.
+ """
if self._heads_provider is not None:
heads = self._heads_provider.heads((left[0], right[0]))
if len(heads) == 1:
@@ -402,10 +426,9 @@
If None, then any ancestry disputes will be resolved with
new_revision_id
"""
- policy = AnnotationPolicy()
+ policy = HeadsAnnotationPolicy(heads_provider)
return policy.reannotate(parents_lines, new_lines, new_revision_id,
- _left_matching_blocks=_left_matching_blocks,
- heads_provider=heads_provider)
+ _left_matching_blocks=_left_matching_blocks)
def _reannotate(parent_lines, new_lines, new_revision_id,
More information about the bazaar-commits
mailing list