Rev 2393: implement several new WorkingTree.move() tests in http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
John Arbash Meinel
john at arbash-meinel.com
Sun Feb 25 18:19:25 GMT 2007
At http://bazaar.launchpad.net/%7Ebzr/bzr/dirstate
------------------------------------------------------------
revno: 2393
revision-id: john at arbash-meinel.com-20070225181821-e55vnu73mm0kzmxe
parent: john at arbash-meinel.com-20070225172022-1lz2vdjp84vp3lu3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate
timestamp: Sun 2007-02-25 12:18:21 -0600
message:
implement several new WorkingTree.move() tests
and fix the bugs in WorkingTree4.move() that it uncovers.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/tests/workingtree_implementations/test_move.py test_move.py-20070225171927-mohn2vqj5fx7edc6-1
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-02-25 16:22:53 +0000
+++ b/bzrlib/dirstate.py 2007-02-25 18:18:21 +0000
@@ -785,8 +785,8 @@
len(self._ghosts))
def _ensure_block(self, parent_block_index, parent_row_index, dirname):
- """Enssure a block for dirname exists.
-
+ """Ensure a block for dirname exists.
+
This function exists to let callers which know that there is a
directory dirname ensure that the block for it exists. This block can
fail to exist because of demand loading, or because a directory had no
@@ -804,7 +804,10 @@
:param dirname: The utf8 dirname to ensure there is a block for.
:return: The index for the block.
"""
- assert dirname != ''
+ if dirname == '' and parent_row_index == 0 and parent_block_index == 0:
+ # This is the signature of the root row, and the
+ # contents-of-root row is always index 1
+ return 1
# the basename of the directory must be the end of its full name.
if not (parent_block_index == -1 and
parent_block_index == -1 and dirname == ''):
@@ -1739,7 +1742,7 @@
some functions. If provided it will be updated if needed.
:return: True if this was the last details entry for they entry key:
that is, if the underlying block has had the entry removed, thus
- shrinking in legnth.
+ shrinking in length.
"""
# build up paths that this id will be left at after the change is made,
# so we can update their cross references in tree 0
=== modified file 'bzrlib/tests/workingtree_implementations/test_move.py'
--- a/bzrlib/tests/workingtree_implementations/test_move.py 2007-02-25 17:20:22 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_move.py 2007-02-25 18:18:21 +0000
@@ -17,6 +17,10 @@
"""Tests for interface conformance of 'workingtree.put_mkdir'"""
+from bzrlib import (
+ errors,
+ )
+
from bzrlib.workingtree_4 import WorkingTreeFormat4
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
@@ -79,3 +83,105 @@
if not isinstance(self.workingtree_format, WorkingTreeFormat4):
raise
+ def test_move_target_not_dir(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a'])
+ tree.add(['a'])
+
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['a'], 'not-a-dir')
+
+ def test_move_non_existent(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a/'])
+ tree.add(['a'])
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['not-a-file'], 'a')
+
+ def test_move_target_not_versioned(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a/', 'b'])
+ tree.add(['b'])
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['b'], 'a')
+
+ # TODO: jam 20070225 What about a test when the target is now a directory,
+ # but in the past it was a file. Theoretically WorkingTree should
+ # notice the kind change.
+
+ def test_move_unversioned(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a/', 'b'])
+ tree.add(['a'])
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['b'], 'a')
+
+ def test_move_multi_unversioned(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a/', 'b', 'c', 'd'])
+ tree.add(['a', 'c', 'd'])
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['c', 'b', 'd'], 'a')
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['b', 'c', 'd'], 'a')
+ self.assertRaises(errors.BzrMoveFailedError,
+ tree.move, ['c', 'd', 'b'], 'a')
+
+ def get_tree_layout(self, tree):
+ """Get the (path, file_id) pairs for the current tree."""
+ tree.lock_read()
+ try:
+ return [(path, ie.file_id) for path, ie
+ in tree.iter_entries_by_dir()]
+ finally:
+ tree.unlock()
+
+ def assertTreeLayout(self, expected, tree):
+ """Check that the tree has the correct layout."""
+ actual = self.get_tree_layout(tree)
+ self.assertEqual(expected, actual)
+
+ def test_move_subdir(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a', 'b/', 'b/c'])
+ tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
+ root_id = tree.get_root_id()
+ self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
+ ('b/c', 'c-id')], tree)
+ a_contents = tree.get_file_text('a-id')
+ tree.move(['a'], 'b')
+ self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
+ ('b/c', 'c-id')], tree)
+ self.failIfExists('a')
+ self.failUnlessExists('b/a')
+ self.check_file_contents('b/a', a_contents)
+
+ def test_move_parent_dir(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a', 'b/', 'b/c'])
+ tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
+ root_id = tree.get_root_id()
+ c_contents = tree.get_file_text('c-id')
+ tree.move(['b/c'], '')
+ self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
+ ('c', 'c-id')], tree)
+ self.failIfExists('b/c')
+ self.failUnlessExists('c')
+ self.check_file_contents('c', c_contents)
+
+ def dont_test(self):
+ self.run_bzr('mv', 'a', 'b')
+ self.assertMoved('a','b')
+
+ self.run_bzr('mv', 'b', 'subdir')
+ self.assertMoved('b','subdir/b')
+
+ self.run_bzr('mv', 'subdir/b', 'a')
+ self.assertMoved('subdir/b','a')
+
+ self.run_bzr('mv', 'a', 'c', 'subdir')
+ self.assertMoved('a','subdir/a')
+ self.assertMoved('c','subdir/c')
+
+ self.run_bzr('mv', 'subdir/a', 'subdir/newa')
+ self.assertMoved('subdir/a','subdir/newa')
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-25 17:20:22 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-25 18:18:21 +0000
@@ -24,6 +24,7 @@
from cStringIO import StringIO
import os
+import sys
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
@@ -484,15 +485,15 @@
rollbacks = []
def rollback_rename():
"""A single rename has failed, roll it back."""
- error = None
+ exc_info = None
for rollback in reversed(rollbacks):
try:
rollback()
except Exception, e:
import pdb;pdb.set_trace()
- error = e
- if error:
- raise error
+ exc_info = sys.exc_info()
+ if exc_info:
+ raise exc_info[0], exc_info[1], exc_info[2]
# perform the disk move first - its the most likely failure point.
from_rel_abs = self.abspath(from_rel)
@@ -546,7 +547,7 @@
id_index=state._get_id_index(),
path_utf8=to_rel.encode('utf8'))
added_entry_index, _ = state._find_entry_index(to_key, to_block[1])
- new_entry = to_block[added_entry_index]
+ new_entry = to_block[1][added_entry_index]
rollbacks.append(lambda:state._make_absent(new_entry))
if new_entry[1][0][0] == 'd':
import pdb;pdb.set_trace()
More information about the bazaar-commits
mailing list