Rev 4522: Add some tests that we can handle doing annotations even when in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

John Arbash Meinel john at arbash-meinel.com
Mon Jul 6 22:13:58 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

------------------------------------------------------------
revno: 4522
revision-id: john at arbash-meinel.com-20090706211330-kwyrjqhhzdo415st
parent: john at arbash-meinel.com-20090706204800-twnc8rfatyaroi1s
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Mon 2009-07-06 16:13:30 -0500
message:
  Add some tests that we can handle doing annotations even when
  one of the parents doesn't have the object as a file.
-------------- next part --------------
=== modified file 'bzrlib/tests/workingtree_implementations/__init__.py'
--- a/bzrlib/tests/workingtree_implementations/__init__.py	2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/workingtree_implementations/__init__.py	2009-07-06 21:13:30 +0000
@@ -63,6 +63,7 @@
     test_workingtree_implementations = [
         'bzrlib.tests.workingtree_implementations.test_add_reference',
         'bzrlib.tests.workingtree_implementations.test_add',
+        'bzrlib.tests.workingtree_implementations.test_annotate_iter',
         'bzrlib.tests.workingtree_implementations.test_basis_inventory',
         'bzrlib.tests.workingtree_implementations.test_basis_tree',
         'bzrlib.tests.workingtree_implementations.test_break_lock',

=== added file 'bzrlib/tests/workingtree_implementations/test_annotate_iter.py'
--- a/bzrlib/tests/workingtree_implementations/test_annotate_iter.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_annotate_iter.py	2009-07-06 21:13:30 +0000
@@ -0,0 +1,134 @@
+# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for interface conformance of 'WorkingTree.annotate_iter'"""
+
+import os
+
+from bzrlib import (
+    errors,
+    inventory,
+    osutils,
+    tests,
+    )
+from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
+
+
+class TestAnnotateIter(TestCaseWithWorkingTree):
+
+    def make_single_rev_tree(self):
+        builder = self.make_branch_builder('branch')
+        builder.build_snapshot('rev-1', None, [
+            ('add', ('', 'TREE_ROOT', 'directory', None)),
+            ('add', ('file', 'file-id', 'file', 'initial content\n')),
+            ])
+        b = builder.get_branch()
+        tree = b.create_checkout('tree', lightweight=True)
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        return tree
+
+    def test_annotate_same_as_parent(self):
+        tree = self.make_single_rev_tree()
+        annotations = tree.annotate_iter('file-id')
+        self.assertEqual([('rev-1', 'initial content\n')],
+                         annotations)
+
+    def test_annotate_mod_from_parent(self):
+        tree = self.make_single_rev_tree()
+        self.build_tree_contents([('tree/file',
+                                   'initial content\nnew content\n')])
+        annotations = tree.annotate_iter('file-id')
+        self.assertEqual([('rev-1', 'initial content\n'),
+                          ('current:', 'new content\n'),
+                         ], annotations)
+
+    def test_annotate_merge_parents(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('rev-1', None, [
+            ('add', ('', 'TREE_ROOT', 'directory', None)),
+            ('add', ('file', 'file-id', 'file', 'initial content\n')),
+            ])
+        builder.build_snapshot('rev-2', ['rev-1'], [
+            ('modify', ('file-id', 'initial content\ncontent in 2\n')),
+            ])
+        builder.build_snapshot('rev-3', ['rev-1'], [
+            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
+            ])
+        builder.finish_series()
+        b = builder.get_branch()
+        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+        tree.set_parent_ids(['rev-2', 'rev-3'])
+        self.build_tree_contents([('tree/file',
+                                   'initial content\ncontent in 2\n'
+                                   'content in 3\nnew content\n')])
+        annotations = tree.annotate_iter('file-id')
+        self.assertEqual([('rev-1', 'initial content\n'),
+                          ('rev-2', 'content in 2\n'),
+                          ('rev-3', 'content in 3\n'),
+                          ('current:', 'new content\n'),
+                         ], annotations)
+
+    def test_annotate_merge_parent_no_file(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('rev-1', None, [
+            ('add', ('', 'TREE_ROOT', 'directory', None)),
+            ])
+        builder.build_snapshot('rev-2', ['rev-1'], [
+            ('add', ('file', 'file-id', 'file', 'initial content\n')),
+            ])
+        builder.build_snapshot('rev-3', ['rev-1'], [])
+        builder.finish_series()
+        b = builder.get_branch()
+        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+        tree.set_parent_ids(['rev-2', 'rev-3'])
+        self.build_tree_contents([('tree/file',
+                                   'initial content\nnew content\n')])
+        annotations = tree.annotate_iter('file-id')
+        self.assertEqual([('rev-2', 'initial content\n'),
+                          ('current:', 'new content\n'),
+                         ], annotations)
+
+    def test_annotate_merge_parent_was_directory(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('rev-1', None, [
+            ('add', ('', 'TREE_ROOT', 'directory', None)),
+            ])
+        builder.build_snapshot('rev-2', ['rev-1'], [
+            ('add', ('file', 'file-id', 'file', 'initial content\n')),
+            ])
+        builder.build_snapshot('rev-3', ['rev-1'], [
+            ('add', ('a_dir', 'file-id', 'directory', None)),
+            ])
+        builder.finish_series()
+        b = builder.get_branch()
+        tree = b.create_checkout('tree', revision_id='rev-2', lightweight=True)
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+        tree.set_parent_ids(['rev-2', 'rev-3'])
+        self.build_tree_contents([('tree/file',
+                                   'initial content\nnew content\n')])
+        annotations = tree.annotate_iter('file-id')
+        self.assertEqual([('rev-2', 'initial content\n'),
+                          ('current:', 'new content\n'),
+                         ], annotations)

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2009-07-06 20:48:00 +0000
+++ b/bzrlib/workingtree.py	2009-07-06 21:13:30 +0000
@@ -489,6 +489,11 @@
                 if file_id not in parent_tree:
                     continue
                 ie = parent_tree.inventory[file_id]
+                if ie.kind != 'file':
+                    # Note: this is slightly unnecessary, because symlinks and
+                    # directories have a "text" which is the empty text, and we
+                    # know that won't mess up annotations. But it seems cleaner
+                    continue
                 parent_text_key = (file_id, ie.revision)
                 if parent_text_key not in maybe_file_parent_keys:
                     maybe_file_parent_keys.append(parent_text_key)



More information about the bazaar-commits mailing list