Rev 2503: Tree.id2path should raise NoSuchId, not return None. in file:///home/mbp/bzr/Work/dirstate/
Martin Pool
mbp at sourcefrog.net
Mon Mar 5 03:56:17 GMT 2007
------------------------------------------------------------
revno: 2503
revision-id: mbp at sourcefrog.net-20070305035531-1t1wn6oy526vrb0q
parent: mbp at sourcefrog.net-20070305034510-w28mfl0bv7qxlbvo
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: dirstate
timestamp: Mon 2007-03-05 14:55:31 +1100
message:
Tree.id2path should raise NoSuchId, not return None.
Add tree implementation test for this and update WorkingTree_4.
modified:
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
bzrlib/tree.py tree.py-20050309040759-9d5f2496be663e77
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2007-02-28 15:41:01 +0000
+++ b/bzrlib/inventory.py 2007-03-05 03:55:31 +0000
@@ -1192,7 +1192,7 @@
try:
ie = self._byid[file_id]
except KeyError:
- raise BzrError("file_id {%s} not found in inventory" % file_id)
+ raise errors.NoSuchId(tree=None, file_id=file_id)
yield ie
file_id = ie.parent_id
=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py 2007-03-03 02:21:25 +0000
+++ b/bzrlib/tests/test_workingtree_4.py 2007-03-05 03:55:31 +0000
@@ -422,7 +422,7 @@
self.build_tree(['tree/a', 'tree/b'])
tree.add(['a'], ['a-id'])
self.assertEqual(u'a', tree.id2path('a-id'))
- self.assertIs(None, tree.id2path('a'))
+ self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
tree.commit('a')
tree.add(['b'], ['b-id'])
@@ -430,9 +430,9 @@
self.assertEqual(u'b\xb5rry', tree.id2path('a-id'))
tree.commit(u'b\xb5rry')
tree.unversion(['a-id'])
- self.assertEqual(None, tree.id2path('a-id'))
+ self.assertRaises(errors.NoSuchId, tree.id2path, 'a-id')
self.assertEqual('b', tree.id2path('b-id'))
- self.assertEqual(None, tree.id2path('c-id'))
+ self.assertRaises(errors.NoSuchId, tree.id2path, 'c-id')
def test_set_root_id(self):
# similar to some code that fails in the dirstate-plus-subtree branch
=== modified file 'bzrlib/tests/tree_implementations/test_tree.py'
--- a/bzrlib/tests/tree_implementations/test_tree.py 2007-03-01 16:48:50 +0000
+++ b/bzrlib/tests/tree_implementations/test_tree.py 2007-03-05 03:55:31 +0000
@@ -14,6 +14,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from bzrlib import (
+ errors,
+ )
from bzrlib.tests.tree_implementations import TestCaseWithTree
class TestAnnotate(TestCaseWithTree):
@@ -29,3 +32,18 @@
self.assertEqual(tree_revision, revision)
finally:
tree.unlock()
+
+
+class TestFileIds(TestCaseWithTree):
+
+ def test_id2path(self):
+ # translate from file-id back to path
+ work_tree = self.make_branch_and_tree('wt')
+ tree = self.get_tree_no_parents_abc_content(work_tree)
+ tree.lock_read()
+ try:
+ self.assertEqual(u'a', tree.id2path('a-id'))
+ # other ids give an error- don't return None for this case
+ self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
+ finally:
+ tree.unlock()
=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py 2007-03-05 03:10:21 +0000
+++ b/bzrlib/tree.py 2007-03-05 03:55:31 +0000
@@ -146,6 +146,10 @@
return iter(self.inventory)
def id2path(self, file_id):
+ """Return the path for a file id.
+
+ :raises NoSuchId:
+ """
file_id = osutils.safe_file_id(file_id)
return self.inventory.id2path(file_id)
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-03-05 01:15:25 +0000
+++ b/bzrlib/workingtree_4.py 2007-03-05 03:55:31 +0000
@@ -405,7 +405,7 @@
state = self.current_dirstate()
entry = self._get_entry(file_id=file_id)
if entry == (None, None):
- return None
+ raise errors.NoSuchId(tree=self, file_id=file_id)
path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
return path_utf8.decode('utf8')
More information about the bazaar-commits
mailing list