Rev 2326: Add a test for list_files, and implement it for DirStateRevisionTree in http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
John Arbash Meinel
john at arbash-meinel.com
Fri Feb 16 00:56:35 GMT 2007
At http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
------------------------------------------------------------
revno: 2326
revision-id: john at arbash-meinel.com-20070216005529-97uws9mank4hh12q
parent: john at arbash-meinel.com-20070215231054-4xry7q64qpodj762
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Thu 2007-02-15 18:55:29 -0600
message:
Add a test for list_files, and implement it for DirStateRevisionTree
added:
bzrlib/tests/tree_implementations/test_list_files.py test_list_files.py-20070216005501-cjh6fzprbe9lbs2t-1
modified:
bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== added file 'bzrlib/tests/tree_implementations/test_list_files.py'
--- a/bzrlib/tests/tree_implementations/test_list_files.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/tree_implementations/test_list_files.py 2007-02-16 00:55:29 +0000
@@ -0,0 +1,55 @@
+# 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
+
+"""Test that all trees support Tree.list_files()"""
+
+from bzrlib.tests.tree_implementations import TestCaseWithTree
+
+
+class TestListFiles(TestCaseWithTree):
+
+ def test_list_files_with_root(self):
+ work_tree = self.make_branch_and_tree('wt')
+ tree = self.get_tree_no_parents_abc_content(work_tree)
+ expected = [('', 'V', 'directory', 'root-id'),
+ ('a', 'V', 'file', 'a-id'),
+ ('b', 'V', 'directory', 'b-id'),
+ ('b/c', 'V', 'file', 'c-id'),
+ ]
+ tree.lock_read()
+ try:
+ actual = [(path, status, kind, file_id)
+ for path, status, kind, file_id, ie in
+ tree.list_files(include_root=True)]
+ finally:
+ tree.unlock()
+ self.assertEqual(expected, actual)
+
+ def test_list_files_no_root(self):
+ work_tree = self.make_branch_and_tree('wt')
+ tree = self.get_tree_no_parents_abc_content(work_tree)
+ expected = [('a', 'V', 'file', 'a-id'),
+ ('b', 'V', 'directory', 'b-id'),
+ ('b/c', 'V', 'file', 'c-id'),
+ ]
+ tree.lock_read()
+ try:
+ actual = [(path, status, kind, file_id)
+ for path, status, kind, file_id, ie in
+ tree.list_files(include_root=False)]
+ finally:
+ tree.unlock()
+ self.assertEqual(expected, actual)
=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- a/bzrlib/tests/tree_implementations/__init__.py 2007-02-15 19:37:13 +0000
+++ b/bzrlib/tests/tree_implementations/__init__.py 2007-02-16 00:55:29 +0000
@@ -247,6 +247,7 @@
def test_suite():
result = TestSuite()
test_tree_implementations = [
+ 'bzrlib.tests.tree_implementations.test_list_files',
'bzrlib.tests.tree_implementations.test_revision_tree',
'bzrlib.tests.tree_implementations.test_test_trees',
'bzrlib.tests.tree_implementations.test_tree',
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-15 23:10:54 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-16 00:55:29 +0000
@@ -875,6 +875,16 @@
return None
return ie.executable
+ def list_files(self, include_root=False):
+ # We use a standard implementation, because DirStateRevisionTree is
+ # dealing with one of the parents of the current state
+ inv = self._get_inventory()
+ entries = inv.iter_entries()
+ if self.inventory.root is not None and not include_root:
+ entries.next()
+ for path, entry in entries:
+ yield path, 'V', entry.kind, entry.file_id, entry
+
def lock_read(self):
"""Lock the tree for a set of operations."""
self._locked += 1
More information about the bazaar-commits
mailing list