Rev 2356: Finish making Tree.ids2paths support the file_ids_across_trees api. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/

Robert Collins robertc at robertcollins.net
Thu Feb 22 01:42:09 GMT 2007


At sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/

------------------------------------------------------------
revno: 2356
revision-id: robertc at robertcollins.net-20070222014109-t8lpcgnp6xr63zv8
parent: robertc at robertcollins.net-20070222011730-zff5fh9qvxrcqa56
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Thu 2007-02-22 12:41:09 +1100
message:
  Finish making Tree.ids2paths support the file_ids_across_trees api.
modified:
  bzrlib/tests/workingtree_implementations/test_paths2ids.py test_paths2ids.py-20070222011621-kesvovdwm69nndtx-1
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
=== modified file 'bzrlib/tests/workingtree_implementations/test_paths2ids.py'
--- a/bzrlib/tests/workingtree_implementations/test_paths2ids.py	2007-02-22 01:17:30 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_paths2ids.py	2007-02-22 01:41:09 +0000
@@ -23,21 +23,24 @@
 
 from operator import attrgetter
 
-from bzrlib import errors, inventory
+from bzrlib import errors
 from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
 
 class TestPaths2Ids(TestCaseWithWorkingTree):
 
-    def assertExpectedIds(self, ids, tree, paths, trees=None):
+    def assertExpectedIds(self, ids, tree, paths, trees=None,
+        require_versioned=True):
         """Run paths2ids for tree, and check the result."""
         tree.lock_read()
         if trees:
             map(apply, map(attrgetter('lock_read'), trees))
-            result = tree.paths2ids(paths, trees)
+            result = tree.paths2ids(paths, trees,
+                require_versioned=require_versioned)
             map(apply, map(attrgetter('unlock'), trees))
         else:
-            result = tree.paths2ids(paths)
+            result = tree.paths2ids(paths,
+                require_versioned=require_versioned)
         self.assertEqual(set(ids), result)
         tree.unlock()
 
@@ -130,3 +133,29 @@
         self.assertExpectedIds(
             ['dir', 'child-moves', 'child-stays', 'child-goes', 'new-child'],
             tree, ['dir'], [basis])
+
+    def test_unversioned_one_tree(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/unversioned'])
+        self.assertExpectedIds([], tree, ['unversioned'], require_versioned=False)
+        tree.lock_read()
+        self.assertRaises(errors.PathsNotVersionedError, tree.paths2ids, ['unversioned'])
+        tree.unlock()
+
+    def test_unversioned_multiple_trees(self):
+        # in this test, the path is unversioned in only one tree, but it should
+        # still raise an error.
+        tree = self.make_branch_and_tree('tree')
+        tree.commit('make basis')
+        basis = tree.basis_tree()
+        self.build_tree(['tree/unversioned'])
+        self.assertExpectedIds([], tree, ['unversioned'], [basis],
+            require_versioned=False)
+        tree.lock_read()
+        basis.lock_read()
+        self.assertRaises(errors.PathsNotVersionedError, tree.paths2ids,
+            ['unversioned'], [basis])
+        self.assertRaises(errors.PathsNotVersionedError, basis.paths2ids,
+            ['unversioned'], [tree])
+        basis.unlock()
+        tree.unlock()

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2007-02-22 01:17:30 +0000
+++ b/bzrlib/tree.py	2007-02-22 01:41:09 +0000
@@ -216,7 +216,7 @@
         """Return the id for path in this tree."""
         return self._inventory.path2id(path)
 
-    def paths2ids(self, paths, trees=[]):
+    def paths2ids(self, paths, trees=[], require_versioned=True):
         """Return all the ids that can be reached by walking from paths.
         
         Each path is looked up in each this tree and any extras provided in
@@ -224,8 +224,13 @@
         of a directory that has been renamed under a provided path in this tree
         are all returned, even if none exist until a provided path in this
         tree, and vice versa.
+
+        :param paths: An iterable of paths to start converting to ids from.
+        :param trees: Additional trees to consider.
+        :param require_versioned: If False, do not raise NotVersionedError if
+            an element of paths is not versioned in this tree and all of trees.
         """
-        return find_ids_across_trees(paths, [self] + trees)
+        return find_ids_across_trees(paths, [self] + trees, require_versioned)
 
     def print_file(self, file_id):
         """Print file with id `file_id` to stdout."""



More information about the bazaar-commits mailing list