Rev 3541: Merge in the latest branch builder work in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/merge_lca_multi
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 23 04:00:33 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/merge_lca_multi
------------------------------------------------------------
revno: 3541
revision-id: john at arbash-meinel.com-20080723025925-8k0ornn7gcle8z2g
parent: john at arbash-meinel.com-20080723022704-fgfvo8t4unyl14bw
parent: john at arbash-meinel.com-20080723023509-1t4wkw5wjif7h72i
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: merge_lca_multi
timestamp: Tue 2008-07-22 21:59:25 -0500
message:
Merge in the latest branch builder work
modified:
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/memorytree.py memorytree.py-20060906023413-4wlkalbdpsxi2r4y-1
bzrlib/tests/test_branchbuilder.py test_branchbuilder.p-20070427022007-zlxpqz2lannhk6y8-2
bzrlib/tests/test_memorytree.py test_memorytree.py-20060906023413-4wlkalbdpsxi2r4y-3
------------------------------------------------------------
revno: 3514.1.71
revision-id: john at arbash-meinel.com-20080723023509-1t4wkw5wjif7h72i
parent: john at arbash-meinel.com-20080722204034-x54day968ipfmr1y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: use_branch_builder
timestamp: Tue 2008-07-22 21:35:09 -0500
message:
Implement rename_one on MemoryTree, and expose that in the Branch Builder
modified:
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/memorytree.py memorytree.py-20060906023413-4wlkalbdpsxi2r4y-1
bzrlib/tests/test_branchbuilder.py test_branchbuilder.p-20070427022007-zlxpqz2lannhk6y8-2
bzrlib/tests/test_memorytree.py test_memorytree.py-20060906023413-4wlkalbdpsxi2r4y-3
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py 2008-07-22 20:40:34 +0000
+++ b/bzrlib/branchbuilder.py 2008-07-23 02:35:09 +0000
@@ -142,10 +142,7 @@
to_add_kinds = []
new_contents = {}
to_unversion_ids = []
- # TODO: MemoryTree doesn't support rename() or
- # apply_inventory_delta, so we'll postpone allowing renames
- # for now
- # to_rename = []
+ to_rename = []
for action, info in actions:
if action == 'add':
path, file_id, kind, content = info
@@ -162,6 +159,9 @@
new_contents[file_id] = content
elif action == 'unversion':
to_unversion_ids.append(info)
+ elif action == 'rename':
+ from_relpath, to_relpath = info
+ to_rename.append((from_relpath, to_relpath))
else:
raise errors.UnknownBuildAction(action)
if to_unversion_ids:
@@ -172,6 +172,8 @@
tree.add([path], [file_id], ['directory'])
else:
tree.mkdir(path, file_id)
+ for from_relpath, to_relpath in to_rename:
+ tree.rename_one(from_relpath, to_relpath)
tree.add(to_add_files, to_add_file_ids, to_add_kinds)
for file_id, content in new_contents.iteritems():
tree.put_file_bytes_non_atomic(file_id, content)
=== modified file 'bzrlib/memorytree.py'
--- a/bzrlib/memorytree.py 2008-07-22 18:12:25 +0000
+++ b/bzrlib/memorytree.py 2008-07-23 02:35:09 +0000
@@ -21,10 +21,12 @@
from copy import deepcopy
+import os
from bzrlib import (
errors,
mutabletree,
+ osutils,
revision as _mod_revision,
)
from bzrlib.decorators import needs_read_lock, needs_write_lock
@@ -101,6 +103,14 @@
return None, False, None
return entry.kind, entry.executable, None
+ @needs_tree_write_lock
+ def rename_one(self, from_rel, to_rel):
+ file_id = self.path2id(from_rel)
+ to_dir, to_tail = os.path.split(to_rel)
+ to_parent_id = self.path2id(to_dir)
+ self._file_transport.move(from_rel, to_rel)
+ self._inventory.rename(file_id, to_parent_id, to_tail)
+
def path_content_summary(self, path):
"""See Tree.path_content_summary."""
id = self.path2id(path)
=== modified file 'bzrlib/tests/test_branchbuilder.py'
--- a/bzrlib/tests/test_branchbuilder.py 2008-07-22 20:40:34 +0000
+++ b/bzrlib/tests/test_branchbuilder.py 2008-07-23 02:35:09 +0000
@@ -196,8 +196,23 @@
self.assertRaises(errors.UnknownBuildAction,
builder.build_snapshot, 'B-id', None, [('weirdo', ('foo',))])
- # TODO: rename a file/directory, but rename isn't supported by the
- # MemoryTree api yet, so for now we wait until it is used
+ def test_rename(self):
+ builder = self.build_a_rev()
+ builder.build_snapshot('B-id', None,
+ [('rename', ('a', 'b'))])
+ rev_tree = builder.get_branch().repository.revision_tree('B-id')
+ self.assertTreeShape([(u'', 'a-root-id', 'directory'),
+ (u'b', 'a-id', 'file')], rev_tree)
+
+ def test_rename_into_subdir(self):
+ builder = self.build_a_rev()
+ builder.build_snapshot('B-id', None,
+ [('add', ('dir', 'dir-id', 'directory', None)),
+ ('rename', ('a', 'dir/a'))])
+ rev_tree = builder.get_branch().repository.revision_tree('B-id')
+ self.assertTreeShape([(u'', 'a-root-id', 'directory'),
+ (u'dir', 'dir-id', 'directory'),
+ (u'dir/a', 'a-id', 'file')], rev_tree)
def test_set_parent(self):
builder = self.build_a_rev()
=== modified file 'bzrlib/tests/test_memorytree.py'
--- a/bzrlib/tests/test_memorytree.py 2008-07-22 18:12:25 +0000
+++ b/bzrlib/tests/test_memorytree.py 2008-07-23 02:35:09 +0000
@@ -182,3 +182,42 @@
rev_id = tree.commit('first post')
tree.unlock()
self.assertEqual(rev_id, tree.last_revision())
+
+ def test_rename_file(self):
+ tree = self.make_branch_and_memory_tree('branch')
+ tree.lock_write()
+ self.addCleanup(tree.unlock)
+ tree.add(['', 'foo'], ['root-id', 'foo-id'], ['directory', 'file'])
+ tree.put_file_bytes_non_atomic('foo-id', 'content\n')
+ tree.commit('one', rev_id='rev-one')
+ tree.rename_one('foo', 'bar')
+ self.assertEqual('bar', tree.id2path('foo-id'))
+ self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
+ self.assertRaises(errors.NoSuchFile,
+ tree._file_transport.get_bytes, 'foo')
+ tree.commit('two', rev_id='rev-two')
+ self.assertEqual('content\n', tree._file_transport.get_bytes('bar'))
+ self.assertRaises(errors.NoSuchFile,
+ tree._file_transport.get_bytes, 'foo')
+
+ rev_tree2 = tree.branch.repository.revision_tree('rev-two')
+ self.assertEqual('bar', rev_tree2.id2path('foo-id'))
+ self.assertEqual('content\n', rev_tree2.get_file_text('foo-id'))
+
+ def test_rename_file_to_subdir(self):
+ tree = self.make_branch_and_memory_tree('branch')
+ tree.lock_write()
+ self.addCleanup(tree.unlock)
+ tree.add('')
+ tree.mkdir('subdir', 'subdir-id')
+ tree.add('foo', 'foo-id', 'file')
+ tree.put_file_bytes_non_atomic('foo-id', 'content\n')
+ tree.commit('one', rev_id='rev-one')
+
+ tree.rename_one('foo', 'subdir/bar')
+ self.assertEqual('subdir/bar', tree.id2path('foo-id'))
+ self.assertEqual('content\n',
+ tree._file_transport.get_bytes('subdir/bar'))
+ tree.commit('two', rev_id='rev-two')
+ rev_tree2 = tree.branch.repository.revision_tree('rev-two')
+ self.assertEqual('subdir/bar', rev_tree2.id2path('foo-id'))
More information about the bazaar-commits
mailing list