Rev 2944: Add a couple of basic tests that Tree.iter_entries_by_dir gives the same results as accessing the inventory object and convert commit() to use Tree.iter_entries_by_dir. in http://people.ubuntu.com/~robertc/baz2.0/commit-builder

Robert Collins robertc at robertcollins.net
Fri Oct 26 09:39:26 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/commit-builder

------------------------------------------------------------
revno: 2944
revision-id:robertc at robertcollins.net-20071026083920-k6pqi8emu7flq5po
parent: robertc at robertcollins.net-20071025222300-su77t1h9i8ordpwh
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit-builder
timestamp: Fri 2007-10-26 18:39:20 +1000
message:
  Add a couple of basic tests that Tree.iter_entries_by_dir gives the same results as accessing the inventory object and convert commit() to use Tree.iter_entries_by_dir.
added:
  bzrlib/tests/tree_implementations/test_iter_entries_by_dir.py test_iter_entries_by-20071026083831-i6mx85yrc4l7uq29-1
modified:
  bzrlib/commit.py               commit.py-20050511101309-79ec1a0168e0e825
  bzrlib/tests/inventory_implementations/test_basics.py basics.py-20070903044446-kdjwbiu1p1zi9phs-1
  bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
=== added file 'bzrlib/tests/tree_implementations/test_iter_entries_by_dir.py'
--- a/bzrlib/tests/tree_implementations/test_iter_entries_by_dir.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/tree_implementations/test_iter_entries_by_dir.py	2007-10-26 08:39:20 +0000
@@ -0,0 +1,67 @@
+# Copyright (C) 2007 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
+
+"""Tests for iter_entries_by_dirs tree method."""
+
+from bzrlib.osutils import has_symlinks
+from bzrlib.tests import TestSkipped
+from bzrlib.tests.tree_implementations import TestCaseWithTree
+
+
+class TestIterEntriesByDir(TestCaseWithTree):
+
+    def assertIteratorsEqual(self, iter_a, iter_b):
+        list_a = list(iter_a)
+        list_b = list(iter_b)
+
+    def assertTreeInventoryIteratorsEqual(self, tree):
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        self.assertIteratorsEqual(tree.iter_entries_by_dir(),
+            tree.inventory.iter_entries_by_dir())
+        # listing all file ids should work:
+        all_ids = set()
+        root_id = None
+        for path, entry in tree.iter_entries_by_dir():
+            all_ids.add(entry.file_id)
+        self.assertIteratorsEqual(
+            tree.iter_entries_by_dir(specific_file_ids=all_ids),
+            tree.inventory.iter_entries_by_dir(specific_file_ids=all_ids))
+        # asking for one id should return just it
+        for file_id in all_ids:
+            self.assertIteratorsEqual(
+                tree.iter_entries_by_dir(specific_file_ids=[file_id]),
+                tree.inventory.iter_entries_by_dir(specific_file_ids=[file_id]))
+        # yield_parents should indeed give the parents...
+        # everything:
+        self.assertIteratorsEqual(tree.iter_entries_by_dir(yield_parents=True),
+            tree.inventory.iter_entries_by_dir(yield_parents=True))
+        # per-id
+        for file_id in all_ids:
+            self.assertIteratorsEqual(
+                tree.iter_entries_by_dir(
+                    specific_file_ids=[file_id], yield_parents=True),
+                tree.inventory.iter_entries_by_dir(
+                    specific_file_ids=[file_id], yield_parents=True))
+
+    def test_tree_with_utf8(self):
+        tree = self.get_tree_with_utf8(self.make_branch_and_tree('.'))
+        self.assertTreeInventoryIteratorsEqual(tree)
+
+    def test_complex(self):
+        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
+            has_symlinks())
+        self.assertTreeInventoryIteratorsEqual(tree)

=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py	2007-10-25 22:23:00 +0000
+++ b/bzrlib/commit.py	2007-10-26 08:39:20 +0000
@@ -655,7 +655,7 @@
         # recorded in their previous state. For more details, see
         # https://lists.ubuntu.com/archives/bazaar/2007q3/028476.html.
         if specific_files:
-            for path, old_ie in self.basis_inv.iter_entries_by_dir():
+            for path, old_ie in self.basis_tree.iter_entries_by_dir():
                 if old_ie.file_id in self.builder.new_inventory:
                     # already added - skip.
                     continue
@@ -706,8 +706,7 @@
         deleted_paths = set()
         # XXX: Note that entries may have the wrong kind because the entry does
         # not reflect the status on disk.
-        work_inv = self.work_tree.inventory
-        entries = work_inv.iter_entries_by_dir(
+        entries = self.work_tree.iter_entries_by_dir(
             specific_file_ids=self.specific_file_ids, yield_parents=True)
         for path, existing_ie in entries:
             file_id = existing_ie.file_id

=== modified file 'bzrlib/tests/inventory_implementations/test_basics.py'
--- a/bzrlib/tests/inventory_implementations/test_basics.py	2007-10-25 22:23:00 +0000
+++ b/bzrlib/tests/inventory_implementations/test_basics.py	2007-10-26 08:39:20 +0000
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Tests for different inventory implementations"""
+"""Tests for different inventory implementations."""
 
 # NOTE: Don't import Inventory here, to make sure that we don't accidentally
 # hardcode that when we should be using self.make_inventory

=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py	2007-10-08 07:29:57 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py	2007-10-26 08:39:20 +0000
@@ -325,6 +325,7 @@
         'bzrlib.tests.tree_implementations.test_get_file_mtime',
         'bzrlib.tests.tree_implementations.test_get_symlink_target',
         'bzrlib.tests.tree_implementations.test_inv',
+        'bzrlib.tests.tree_implementations.test_iter_entries_by_dir',
         'bzrlib.tests.tree_implementations.test_list_files',
         'bzrlib.tests.tree_implementations.test_path_content_summary',
         'bzrlib.tests.tree_implementations.test_revision_tree',

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2007-10-11 04:54:04 +0000
+++ b/bzrlib/tree.py	2007-10-26 08:39:20 +0000
@@ -165,7 +165,7 @@
         return self.bzrdir.is_control_filename(filename)
 
     @needs_read_lock
-    def iter_entries_by_dir(self, specific_file_ids=None):
+    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
         """Walk the tree in 'by_dir' order.
 
         This will yield each entry in the tree as a (path, entry) tuple. The
@@ -174,7 +174,7 @@
         directory are grouped together.
         """
         return self.inventory.iter_entries_by_dir(
-            specific_file_ids=specific_file_ids)
+            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
     def iter_references(self):
         for path, entry in self.iter_entries_by_dir():



More information about the bazaar-commits mailing list