Rev 3491: Implement the 'no-merge' policy, we'll want more tests, though. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/annotation

John Arbash Meinel john at arbash-meinel.com
Thu Jun 12 00:10:29 BST 2008


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

------------------------------------------------------------
revno: 3491
revision-id: john at arbash-meinel.com-20080611231018-tbylmdk633nv40x8
parent: john at arbash-meinel.com-20080611223256-m300jv9r7rxsu56w
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: annotation
timestamp: Wed 2008-06-11 18:10:18 -0500
message:
  Implement the 'no-merge' policy, we'll want more tests, though.
-------------- next part --------------
=== modified file 'bzrlib/annotation_policy/__init__.py'
--- a/bzrlib/annotation_policy/__init__.py	2008-06-11 22:32:56 +0000
+++ b/bzrlib/annotation_policy/__init__.py	2008-06-11 23:10:18 +0000
@@ -63,40 +63,69 @@
         :return: A list of annotated lines.
         """
         if len(annotated_parents_lines) == 0:
-            lines = [(child_revision_id, line) for line in plain_child_lines]
+            return self._do_annotate_no_parents(plain_child_lines,
+                                                child_revision_id)
         elif len(annotated_parents_lines) == 1:
-            lines = self._reannotate_one(annotated_parents_lines[0],
-                        plain_child_lines, child_revision_id,
-                        left_matching_blocks)
+            return self._do_annotate_one_parent(annotated_parents_lines[0],
+                left_matching_blocks, plain_child_lines, child_revision_id)
         elif len(annotated_parents_lines) == 2:
-            left = self._reannotate_one(annotated_parents_lines[0],
-                        plain_child_lines, child_revision_id,
-                        left_matching_blocks)
-            lines = self._reannotate_annotated(annotated_parents_lines[1],
-                            plain_child_lines, child_revision_id, left)
+            return self._do_annotate_two_parents(
+                annotated_parents_lines[0], left_matching_blocks,
+                annotated_parents_lines[1], plain_child_lines,
+                child_revision_id)
         else:
-            # Annotate the child lines versus each parent, and then match up the
-            # lines one-by-one
-            reannotations = [self._reannotate_one(annotated_parents_lines[0],
-                                plain_child_lines, child_revision_id,
-                                left_matching_blocks)]
-            reannotations.extend(self._reannotate_one(p, plain_child_lines,
-                                                     child_revision_id)
-                                 for p in annotated_parents_lines[1:])
-            lines = []
-            for annos in zip(*reannotations):
-                origins = set(a for a, l in annos)
+            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."""
+        return [(child_revision_id, line) for line in plain_child_lines]
+
+    def _do_annotate_one_parent(self, annotated_parent_lines, matching_blocks,
+                                plain_child_lines, child_revision_id):
+        """Annotate with only 1 parent to consider"""
+        return self._reannotate_one(annotated_parent_lines, plain_child_lines,
+                                    child_revision_id, matching_blocks)
+
+    def _do_annotate_two_parents(self, first_parent_lines,
+                                 first_matching_blocks,
+                                 second_parent_lines,
+                                 plain_child_lines,
+                                 child_revision_id):
+        """Annotate versus two parents"""
+        left = self._reannotate_one(first_parent_lines,
+                    plain_child_lines, child_revision_id,
+                    first_matching_blocks)
+        return self._reannotate_annotated(second_parent_lines,
+                    plain_child_lines, child_revision_id, left)
+
+    def _do_annotate_many_parents(self, annotated_parent_lines,
+                                  first_matching_blocks, plain_child_lines,
+                                  child_revision_id):
+        # Annotate the child lines versus each parent, and then match up the
+        # lines one-by-one
+        reannotations = [self._reannotate_one(annotated_parents_lines[0],
+                            plain_child_lines, child_revision_id,
+                            left_matching_blocks)]
+        reannotations.extend(self._reannotate_one(p, plain_child_lines,
+                                                 child_revision_id)
+                             for p in annotated_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 child_revision_id in origins:
+                    origins.remove(child_revision_id)
                 if len(origins) == 1:
-                    # All the parents agree, so just return the first one
-                    lines.append(annos[0])
+                    lines.append((origins.pop(), line))
                 else:
-                    line = annos[0][1]
-                    if len(origins) == 2 and child_revision_id in origins:
-                        origins.remove(child_revision_id)
-                    if len(origins) == 1:
-                        lines.append((origins.pop(), line))
-                    else:
-                        lines.append((child_revision_id, line))
+                    lines.append((child_revision_id, line))
         return lines
 
     def _reannotate_one(self, annotated_parent_lines, plain_child_lines,
@@ -274,4 +303,8 @@
     'bzrlib.annotation_policy.left', 'LeftHeadAnnotationPolicy',
     help="Assign ambiguous lines to the basis tree"
          " (after checking heads())")
+registry.register_lazy('no-merge',
+    'bzrlib.annotation_policy.no_merge', 'NoMergeAnnotationPolicy',
+    help="Don't consider the ancestry in merges when determining"
+         " annotations.")
 registry.default_key = 'merge-node'

=== added file 'bzrlib/annotation_policy/no_merge.py'
--- a/bzrlib/annotation_policy/no_merge.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/annotation_policy/no_merge.py	2008-06-11 23:10:18 +0000
@@ -0,0 +1,42 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Annotate by assigning all lines based on the primary parent"""
+
+from bzrlib import annotation_policy
+
+
+class NoMergeAnnotationPolicy(annotation_policy.AnnotationPolicy):
+    """Assign all lines based on the primary parent"""
+
+    def _do_annotate_two_parents(self, first_parent_lines,
+                                 first_matching_blocks,
+                                 second_parent_lines,
+                                 plain_child_lines,
+                                 child_revision_id):
+        """Annotate versus two parents,
+        
+        For this class, we always ignore other parents.
+        """
+        return self._do_annotate_one_parent(first_parent_lines,
+            first_matching_blocks, plain_child_lines, child_revision_id)
+
+    def _do_annotate_many_parents(self, annotated_parent_lines,
+                                  first_matching_blocks, plain_child_lines,
+                                  child_revision_id):
+        return self._do_annotate_one_parent(annotated_parent_lines[0],
+            first_matching_blocks, plain_child_lines, child_revision_id)
+

=== modified file 'bzrlib/tests/test_annotation_policy.py'
--- a/bzrlib/tests/test_annotation_policy.py	2008-06-11 22:32:56 +0000
+++ b/bzrlib/tests/test_annotation_policy.py	2008-06-11 23:10:18 +0000
@@ -295,7 +295,7 @@
      'rev-E':[(1, 'rev-A', 'alt-second\n')],
     })
 
-DuplicateLineScenario(['left-head', 'simple-left'],
+DuplicateLineScenario(['left-head', 'simple-left', 'no-merge'],
     {'rev-D':[(1, 'rev-B', 'alt-second\n')],
      'rev-E':[(1, 'rev-A', 'alt-second\n')],
     })
@@ -333,7 +333,7 @@
 MergeRevertedLineScenario(['merge-node', 'right-head', 'simple-right',
                            'left-head'],
     {'rev-E':[(0, 'rev-D', 'foo\n')]})
-MergeRevertedLineScenario(['simple-left'],
+MergeRevertedLineScenario(['simple-left', 'no-merge'],
     {'rev-E':[(0, 'rev-A', 'foo\n')]})
 
 
@@ -363,7 +363,7 @@
 
 # Currently all implementations offer this value
 TrunkRevertedLineScenario(['merge-node', 'right-head', 'left-head',
-                           'simple-left'],
+                           'simple-left', 'no-merge'],
     {'rev-E':[(0, 'rev-D', 'foo\n')]})
 # simple-right always assumes that the right branch is correct, so it changes
 # the value



More information about the bazaar-commits mailing list