Rev 2945: Add an all_file_ids method on tree to access the entire set of id's, used in commit to detect deletes. in http://people.ubuntu.com/~robertc/baz2.0/commit-builder

Robert Collins robertc at robertcollins.net
Sat Oct 27 00:29:53 BST 2007


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

------------------------------------------------------------
revno: 2945
revision-id:robertc at robertcollins.net-20071026232936-l26eaa4zmmmrfq3f
parent: robertc at robertcollins.net-20071026083920-k6pqi8emu7flq5po
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit-builder
timestamp: Sat 2007-10-27 09:29:36 +1000
message:
  Add an all_file_ids method on tree to access the entire set of id's, used in commit to detect deletes.
added:
  bzrlib/tests/tree_implementations/test_all_file_ids.py test_all_file_ids.py-20071026232254-opsgahreyb17p7ph-1
modified:
  bzrlib/commit.py               commit.py-20050511101309-79ec1a0168e0e825
  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_all_file_ids.py'
--- a/bzrlib/tests/tree_implementations/test_all_file_ids.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/tree_implementations/test_all_file_ids.py	2007-10-26 23:29:36 +0000
@@ -0,0 +1,38 @@
+# 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 the all_file_ids method."""
+
+from bzrlib.osutils import has_symlinks
+from bzrlib.tests.tree_implementations import TestCaseWithTree
+
+
+class TestAllFileIds(TestCaseWithTree):
+
+    def assertTreeInventoryIteratorsEqual(self, tree):
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        self.assertEqual(tree.all_file_ids(),
+            set(tree.inventory._byid.keys()))
+
+    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-26 08:39:20 +0000
+++ b/bzrlib/commit.py	2007-10-26 23:29:36 +0000
@@ -682,7 +682,7 @@
     def _report_and_accumulate_deletes(self):
         # XXX: Could the list of deleted paths and ids be instead taken from
         # _populate_from_inventory?
-        deleted_ids = set(self.basis_inv._byid.keys()) - \
+        deleted_ids = self.basis_tree.all_file_ids() - \
             set(self.builder.new_inventory._byid.keys())
         if deleted_ids:
             self.any_entries_deleted = True

=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py	2007-10-26 08:39:20 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py	2007-10-26 23:29:36 +0000
@@ -322,6 +322,7 @@
 def test_suite():
     result = TestSuite()
     test_tree_implementations = [
+        'bzrlib.tests.tree_implementations.test_all_file_ids',
         'bzrlib.tests.tree_implementations.test_get_file_mtime',
         'bzrlib.tests.tree_implementations.test_get_symlink_target',
         'bzrlib.tests.tree_implementations.test_inv',

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2007-10-26 08:39:20 +0000
+++ b/bzrlib/tree.py	2007-10-26 23:29:36 +0000
@@ -277,6 +277,10 @@
         """
         raise NotImplementedError(self.get_symlink_target)
 
+    def all_file_ids(self):
+        """Return a set of all the fileids present in the tree."""
+        return set(self.inventory._byid.iterkeys())
+
     def annotate_iter(self, file_id):
         """Return an iterator of revision_id, line tuples.
 



More information about the bazaar-commits mailing list