Rev 2452: Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them. in http://bazaar.launchpad.net/~bzr/bzr/dirstate

Robert Collins robertc at robertcollins.net
Thu Mar 1 03:21:23 GMT 2007


At http://bazaar.launchpad.net/~bzr/bzr/dirstate

------------------------------------------------------------
revno: 2452
revision-id: robertc at robertcollins.net-20070301032019-s9lbs2lv8xa6zqxk
parent: robertc at robertcollins.net-20070301025530-4yx1nlo3ze29bajg
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Thu 2007-03-01 14:20:19 +1100
message:
  Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
modified:
  bzrlib/tests/workingtree_implementations/test_move.py test_move.py-20070225171927-mohn2vqj5fx7edc6-1
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/tests/workingtree_implementations/test_move.py'
--- a/bzrlib/tests/workingtree_implementations/test_move.py	2007-02-26 16:19:02 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_move.py	2007-03-01 03:20:19 +0000
@@ -52,7 +52,8 @@
         tree = self.make_branch_and_tree('.')
         tree.add(['a1', 'sub1'])
         tree.commit('initial commit')
-        tree.move(['a1'], to_dir='sub1', after=False)
+        self.assertEqual([('a1', 'sub1/a1')],
+            tree.move(['a1'], to_dir='sub1', after=False))
 
     def test_move_correct_call_unnamed(self):
         """tree.move has the deprecated parameter 'to_name'.
@@ -63,7 +64,8 @@
         tree = self.make_branch_and_tree('.')
         tree.add(['a1', 'sub1'])
         tree.commit('initial commit')
-        tree.move(['a1'], 'sub1', after=False)
+        self.assertEqual([('a1', 'sub1/a1')],
+            tree.move(['a1'], 'sub1', after=False))
 
     def test_move_deprecated_wrong_call(self):
         """tree.move has the deprecated parameter 'to_name'.
@@ -171,7 +173,8 @@
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('b/c', 'c-id')], tree.basis_tree())
         a_contents = tree.get_file_text('a-id')
-        tree.move(['a'], 'b')
+        self.assertEqual([('a', 'b/a')],
+            tree.move(['a'], 'b'))
         self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
                                ('b/c', 'c-id')], tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
@@ -186,7 +189,8 @@
         tree.commit('initial', rev_id='rev-1')
         root_id = tree.get_root_id()
         c_contents = tree.get_file_text('c-id')
-        tree.move(['b/c'], '')
+        self.assertEqual([('b/c', 'c')],
+            tree.move(['b/c'], ''))
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('c', 'c-id')], tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
@@ -245,7 +249,8 @@
                               tree)
         # We don't need after=True as long as source is missing and target
         # exists.
-        tree.move(['a'], 'b')
+        self.assertEqual([('a', 'b/a')],
+            tree.move(['a'], 'b'))
         self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
                               tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
@@ -262,7 +267,8 @@
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
                               tree)
         # Passing after=True should work as well
-        tree.move(['a'], 'b', after=True)
+        self.assertEqual([('a', 'b/a')],
+            tree.move(['a'], 'b', after=True))
         self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
                               tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
@@ -310,7 +316,8 @@
         self.assertFileEqual(a_text, 'a')
         self.assertFileEqual(ba_text, 'b/a')
         # But you can pass after=True
-        tree.move(['a'], 'b', after=True)
+        self.assertEqual([('a', 'b/a')],
+            tree.move(['a'], 'b', after=True))
         self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
                               tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
@@ -327,7 +334,8 @@
         tree.commit('initial', rev_id='rev-1')
         root_id = tree.get_root_id()
 
-        tree.move(['a'], 'e')
+        self.assertEqual([('a', 'e/a')],
+            tree.move(['a'], 'e'))
         self.assertTreeLayout([('', root_id), ('e', 'e-id'), ('e/a', 'a-id'),
                                ('e/a/b', 'b-id'), ('e/a/c', 'c-id'),
                                ('e/a/c/d', 'd-id')], tree)
@@ -343,13 +351,15 @@
         tree.commit('initial', rev_id='rev-1')
         root_id = tree.get_root_id()
 
-        tree.move(['a/b'], 'c')
+        self.assertEqual([('a/b', 'c/b')],
+            tree.move(['a/b'], 'c'))
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                                ('c/b', 'b-id')], tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                                ('a/b', 'b-id')], tree.basis_tree())
 
-        tree.move(['c/b'], '')
+        self.assertEqual([('c/b', 'b')],
+            tree.move(['c/b'], ''))
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('c', 'c-id')], tree)
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-03-01 02:55:30 +0000
+++ b/bzrlib/workingtree_4.py	2007-03-01 03:20:19 +0000
@@ -443,8 +443,9 @@
     @needs_tree_write_lock
     def move(self, from_paths, to_dir, after=False):
         """See WorkingTree.move()."""
+        result = []
         if not from_paths:
-            return ()
+            return result
 
         state = self.current_dirstate()
 
@@ -652,10 +653,11 @@
             except:
                 rollback_rename()
                 raise
+            result.append((from_rel, to_rel))
             state._dirblock_state = dirstate.DirState.IN_MEMORY_MODIFIED
             self._dirty = True
 
-        return #rename_tuples
+        return result
 
     def _new_tree(self):
         """Initialize the state in this tree to be a new tree."""



More information about the bazaar-commits mailing list