Rev 3494: Some review feedback from Ian. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation

John Arbash Meinel john at arbash-meinel.com
Tue Jun 17 21:41:29 BST 2008


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

------------------------------------------------------------
revno: 3494
revision-id: john at arbash-meinel.com-20080617204106-lksom3sdqjt5sx5f
parent: john at arbash-meinel.com-20080612163311-977q08c89jqwjcul
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Tue 2008-06-17 15:41:06 -0500
message:
  Some review feedback from Ian.
  
  Simplify the _resolve_ambiguous api.
-------------- next part --------------
=== modified file 'bzrlib/annotate.py'
--- a/bzrlib/annotate.py	2008-06-11 18:11:44 +0000
+++ b/bzrlib/annotate.py	2008-06-17 20:41:06 +0000
@@ -169,8 +169,6 @@
         (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
     """
     from bzrlib import annotation_policy
     policy = annotation_policy.registry.get()(heads_provider)

=== modified file 'bzrlib/annotation_policy/__init__.py'
--- a/bzrlib/annotation_policy/__init__.py	2008-06-12 16:33:11 +0000
+++ b/bzrlib/annotation_policy/__init__.py	2008-06-17 20:41:06 +0000
@@ -34,12 +34,12 @@
     """
 
     def __init__(self, heads_provider):
-        """Create a new AnnotationPolicy
+        """Create a new AnnotationPolicy.
 
-        :param heads_provider: An object which provids a .heads() call to
+        :param heads_provider: An object which provides a .heads() call to
             resolve if any revision ids are children of others.
             Should also provide a 'cache(keys, head)' function.
-            Can be None.
+            
         """
         self._sequence_matcher = patiencediff.PatienceSequenceMatcher
         self._heads_provider = heads_provider
@@ -77,7 +77,6 @@
             return self._do_annotate_many_parents(
                 annotated_parents_lines, left_matching_blocks,
                 plain_child_lines, child_revision_id)
-        return lines
 
     def _do_annotate_no_parents(self, plain_child_lines, child_revision_id):
         """Simplest case, no parents to consider."""
@@ -153,7 +152,7 @@
             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])
+                                                :start_parent + match_len])
             last_child_match = start_child + match_len
         return lines
 
@@ -209,7 +208,7 @@
                                 annotated_child_lines, start_child, end_child,
                                 annotated_right_lines, start_right, end_right,
                                 revision_id):
-        """Find lines in plain right_lines that match plain_child_lines
+        """Find lines in plain right_lines that match plain_child_lines.
 
         :param output_lines: Append final annotated lines to this list
         :param plain_child_lines: The unannotated new lines for the child text
@@ -244,8 +243,8 @@
                 output_extend(annotated_child_lines[
                     start_child + last_child_idx:start_child + child_idx])
             for offset in xrange(match_len):
-                left = annotated_child_lines[start_child+child_idx+offset]
-                right = annotated_right_lines[start_right+right_idx+offset]
+                left = annotated_child_lines[start_child + child_idx + offset]
+                right = annotated_right_lines[start_right + right_idx + offset]
                 if left[0] == right[0]:
                     # The annotations match, just return the left one
                     output_append(left)
@@ -255,11 +254,11 @@
                     output_append(right)
                 else:
                     # Left and Right both claim this line
-                    output_append(self._resolve_ambiguous(revision_id, left,
-                                                          right))
+                    output_append((self._resolve_ambiguous(revision_id,
+                                    left[0], right[0]), left[1]))
             last_child_idx = child_idx + match_len
 
-    def _resolve_ambiguous(self, revision_id, left, right):
+    def _resolve_ambiguous(self, revision_id, left_parent_id, right_parent_id):
         """Resolve an ambiguous annotation between texts.
 
         This is the thunk layer, implementations should override
@@ -267,15 +266,19 @@
 
         :param revision_id: The revision id to assign if this line is
             considered newly introduced.
-        :param left: (left_parent_id, text)
-        :param right: (right_parent_id, text)
-        :return: (annotation_id, text)
+        :param left_parent_id: The revision id the left parent assigned to this
+            line
+        :param right_parent_id: The revision id the right parent assigned to
+            this line
+        :return: annotation_id
         """
         # TODO: Would it be cleaner to just pass in the revision ids, rather
         #       than (revision_id, text)?
-        return self._do_resolve_ambiguous(revision_id, left, right)
+        return self._do_resolve_ambiguous(revision_id, left_parent_id,
+                                          right_parent_id)
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """See AnnotationPolicy._resolve_ambiguous
         
         This is intended to be overriden by implementations.

=== modified file 'bzrlib/annotation_policy/left.py'
--- a/bzrlib/annotation_policy/left.py	2008-06-11 22:32:56 +0000
+++ b/bzrlib/annotation_policy/left.py	2008-06-17 20:41:06 +0000
@@ -22,23 +22,25 @@
 class SimpleLeftAnnotationPolicy(annotation_policy.AnnotationPolicy):
     """Assign ambiguous lines to the left parent."""
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """See AnnotationPolicy._do_resolve_ambiguous"""
         # Always return left
-        return left
+        return left_parent_id
 
 
 class LeftHeadAnnotationPolicy(annotation_policy.AnnotationPolicy):
     """Assign ambiguous lines to the first parent."""
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """See AnnotationPolicy._do_resolve_ambiguous"""
         if self._heads_provider is None:
             return left
-        heads = self._heads_provider.heads((left[0], right[0]))
+        heads = self._heads_provider.heads((left_parent_id, right_parent_id))
         if len(heads) == 1:
-            return (iter(heads).next(), left[1])
+            return iter(heads).next()
         else:
             # Both claim different origins
             # give it to left
-            return left
+            return left_parent_id

=== modified file 'bzrlib/annotation_policy/merge_node.py'
--- a/bzrlib/annotation_policy/merge_node.py	2008-06-11 18:11:44 +0000
+++ b/bzrlib/annotation_policy/merge_node.py	2008-06-17 20:41:06 +0000
@@ -22,25 +22,26 @@
 class MergeNodeAnnotationPolicy(annotation_policy.AnnotationPolicy):
     """Assign ambiguous lines to the node merging the results."""
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """We have an ambiguous line between two texts.
         
         Resolve this somehow.
         """
         if self._heads_provider is None:
             # Without a heads provider, we just always pick 'tip'
-            return (revision_id, left[1])
-        heads = self._heads_provider.heads((left[0], right[0]))
+            return revision_id
+        heads = self._heads_provider.heads((left_parent_id, right_parent_id))
         if len(heads) == 1:
-            return (iter(heads).next(), left[1])
+            return iter(heads).next()
         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, left_parent_id),
                 (revision_id,))
             self._heads_provider.cache(
-                (revision_id, right[0]),
+                (revision_id, right_parent_id),
                 (revision_id,))
-            return (revision_id, left[1])
+            return revision_id

=== modified file 'bzrlib/annotation_policy/right.py'
--- a/bzrlib/annotation_policy/right.py	2008-06-11 22:32:56 +0000
+++ b/bzrlib/annotation_policy/right.py	2008-06-17 20:41:06 +0000
@@ -22,23 +22,25 @@
 class SimpleRightAnnotationPolicy(annotation_policy.AnnotationPolicy):
     """Assign ambiguous lines to the right parent."""
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """See AnnotationPolicy._do_resolve_ambiguous"""
         # Always return right
-        return right
+        return right_parent_id
 
 
 class RightHeadAnnotationPolicy(annotation_policy.AnnotationPolicy):
     """Assign ambiguous lines to the last merge parent."""
 
-    def _do_resolve_ambiguous(self, revision_id, left, right):
+    def _do_resolve_ambiguous(self, revision_id, left_parent_id,
+                              right_parent_id):
         """See AnnotationPolicy._do_resolve_ambiguous"""
         if self._heads_provider is None:
-            return right
-        heads = self._heads_provider.heads((left[0], right[0]))
+            return right_parent_id
+        heads = self._heads_provider.heads((left_parent_id, right_parent_id))
         if len(heads) == 1:
-            return (iter(heads).next(), left[1])
+            return iter(heads).next()
         else:
             # Both claim different origins
             # give it to right
-            return right
+            return right_parent_id



More information about the bazaar-commits mailing list