Rev 3574: Revert back to using MemoryTree.mkdir() rather than creating the directory during add(). in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder
John Arbash Meinel
john at arbash-meinel.com
Tue Jul 22 19:13:29 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder
------------------------------------------------------------
revno: 3574
revision-id: john at arbash-meinel.com-20080722181225-nx1dwfmb4wky600x
parent: john at arbash-meinel.com-20080722180140-oesgtrbjpyd8dzik
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: branch_builder
timestamp: Tue 2008-07-22 13:12:25 -0500
message:
Revert back to using MemoryTree.mkdir() rather than creating the directory during add().
This complicates the api a bit, because we have to use multiple passes,
but at least we don't change any tested behavior.
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py 2008-07-22 17:35:59 +0000
+++ b/bzrlib/branchbuilder.py 2008-07-22 18:12:25 +0000
@@ -64,7 +64,12 @@
tree = memorytree.MemoryTree.create_on_branch(self._branch)
tree.lock_write()
try:
- to_add_paths = []
+ # Unfortunately, MemoryTree.add(directory) just creates an
+ # inventory entry. And the only public function to create a
+ # directory is MemoryTree.mkdir() which creates the directory, but
+ # also always adds it. So we have to use a multi-pass setup.
+ to_add_directories = []
+ to_add_files = []
to_add_file_ids = []
to_add_kinds = []
new_contents = {}
@@ -73,11 +78,14 @@
for action, info in actions:
if action == 'add':
path, file_id, kind, content = info
- to_add_paths.append(path)
- to_add_file_ids.append(file_id)
- to_add_kinds.append(kind)
- if content is not None:
- new_contents[file_id] = content
+ if kind == 'directory':
+ to_add_directories.append((path, file_id))
+ else:
+ to_add_files.append(path)
+ to_add_file_ids.append(file_id)
+ to_add_kinds.append(kind)
+ if content is not None:
+ new_contents[file_id] = content
elif action == 'modify':
file_id, content = info
new_contents[file_id] = content
@@ -87,7 +95,13 @@
raise errors.UnknownBuildAction(action)
if to_unversion_ids:
tree.unversion(to_unversion_ids)
- tree.add(to_add_paths, to_add_file_ids, to_add_kinds)
+ for path, file_id in to_add_directories:
+ if path == '':
+ # Special case, because the path already exists
+ tree.add([path], [file_id], ['directory'])
+ else:
+ tree.mkdir(path, file_id)
+ 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 17:59:57 +0000
+++ b/bzrlib/memorytree.py 2008-07-22 18:12:25 +0000
@@ -59,8 +59,6 @@
self._inventory.add_path(f, kind=kind)
else:
self._inventory.add_path(f, kind=kind, file_id=file_id)
- if kind == 'directory' and f != '':
- self._file_transport.mkdir(f)
def basis_tree(self):
"""See Tree.basis_tree()."""
=== modified file 'bzrlib/tests/test_branchbuilder.py'
--- a/bzrlib/tests/test_branchbuilder.py 2008-07-22 18:01:40 +0000
+++ b/bzrlib/tests/test_branchbuilder.py 2008-07-22 18:12:25 +0000
@@ -120,6 +120,16 @@
(u'b', 'b-id', 'file')], rev_tree)
self.assertEqual('content_b', rev_tree.get_file_text('b-id'))
+ def test_add_empty_dir(self):
+ builder = self.build_a_rev()
+ rev_id2 = builder.build_snapshot(None, 'B-id',
+ [('add', ('b', 'b-id', 'directory', None))])
+ rev_tree = builder.get_branch().repository.revision_tree('B-id')
+ self.assertTreeShape([(u'', 'a-root-id', 'directory'),
+ (u'a', 'a-id', 'file'),
+ (u'b', 'b-id', 'directory'),
+ ], rev_tree)
+
def test_modify_file(self):
builder = self.build_a_rev()
rev_id2 = builder.build_snapshot(None, 'B-id',
=== modified file 'bzrlib/tests/test_memorytree.py'
--- a/bzrlib/tests/test_memorytree.py 2008-07-22 17:59:57 +0000
+++ b/bzrlib/tests/test_memorytree.py 2008-07-22 18:12:25 +0000
@@ -101,7 +101,7 @@
self.assertEqual('afile', tree.id2path(tree.path2id('afile')))
self.assertEqual('adir', tree.id2path(tree.path2id('adir')))
self.assertFalse(tree.has_filename('afile'))
- self.assertTrue(tree.has_filename('adir'))
+ self.assertFalse(tree.has_filename('adir'))
tree.unlock()
def test_put_new_file(self):
@@ -130,8 +130,13 @@
tree = MemoryTree.create_on_branch(branch)
tree.lock_write()
self.addCleanup(tree.unlock)
- tree.add(['', 'adir', 'adir/afile'], ['root-id', 'dir-id', 'file-id'],
- ['directory', 'directory', 'file'])
+ tree.add([''], ['root-id'], ['directory'])
+ # Unfortunately, the only way to 'mkdir' is to call 'tree.mkdir', but
+ # that *always* adds the directory as well. So if you want to create a
+ # file in a subdirectory, you have to split out the 'mkdir()' calls
+ # from the add and put_file_bytes_non_atomic calls. :(
+ tree.mkdir('adir', 'dir-id')
+ tree.add(['adir/afile'], ['file-id'], ['file'])
self.assertEqual('adir/afile', tree.id2path('file-id'))
self.assertEqual('adir', tree.id2path('dir-id'))
tree.put_file_bytes_non_atomic('file-id', 'barshoom')
More information about the bazaar-commits
mailing list