Rev 3568: Initial work to have BranchBuilder allow us to do tree-shape work. in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

John Arbash Meinel john at arbash-meinel.com
Tue Jul 22 18:04:58 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

------------------------------------------------------------
revno: 3568
revision-id: john at arbash-meinel.com-20080722170355-00mcj4j1a8pdsout
parent: pqm at pqm.ubuntu.com-20080721151553-11iasd1407hkznk1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: branch_builder
timestamp: Tue 2008-07-22 12:03:55 -0500
message:
  Initial work to have BranchBuilder allow us to do tree-shape work.
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py	2007-04-27 06:16:29 +0000
+++ b/bzrlib/branchbuilder.py	2008-07-22 17:03:55 +0000
@@ -60,6 +60,32 @@
         finally:
             tree.unlock()
 
+    def build_snapshot(self, parent_ids, revision_id, actions):
+        tree = memorytree.MemoryTree.create_on_branch(self._branch)
+        tree.lock_write()
+        try:
+            to_add_paths = []
+            to_add_file_ids = []
+            to_add_kinds = []
+            to_add_contents = {}
+            # to_remove = []
+            # to_rename = []
+            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:
+                        to_add_contents[file_id] = content
+            tree.add(to_add_paths, to_add_file_ids, to_add_kinds)
+            for file_id, content in to_add_contents.iteritems():
+                tree.put_file_bytes_non_atomic(file_id, content)
+
+            return tree.commit('commit %s' % (revision_id,), rev_id=revision_id)
+        finally:
+            tree.unlock()
+
     def get_branch(self):
         """Return the branch created by the builder."""
         return self._branch

=== modified file 'bzrlib/tests/test_branchbuilder.py'
--- a/bzrlib/tests/test_branchbuilder.py	2007-04-27 06:16:29 +0000
+++ b/bzrlib/tests/test_branchbuilder.py	2008-07-22 17:03:55 +0000
@@ -26,6 +26,9 @@
 
 class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
     
+    def assertTreeShape(self, entries, tree):
+        """Check that the tree shape matches expectations."""
+
     def test_create(self):
         """Test the constructor api."""
         builder = BranchBuilder(self.get_transport().clone('foo'))
@@ -71,3 +74,20 @@
         self.assertEqual(
             [rev_id1],
             branch.repository.get_revision(branch.last_revision()).parent_ids)
+
+    def test_build_snapshot(self):
+        builder = BranchBuilder(self.get_transport().clone('foo'))
+        rev_id1 = builder.build_snapshot(None, 'A-id',
+            [('add', ('', 'a-root-id', 'directory', None)),
+             ('add', ('a', 'a-id', 'file', 'contents'))])
+        self.assertEqual('A-id', rev_id1)
+        branch = builder.get_branch()
+        self.assertEqual((1, rev_id1), branch.last_revision_info())
+        rev_tree = branch.repository.revision_tree(rev_id1)
+        rev_tree.lock_read()
+        self.addCleanup(rev_tree.unlock)
+        entries = [(path, ie.file_id, ie.kind)
+                   for path, ie in rev_tree.iter_entries_by_dir()]
+        self.assertEqual([(u'', 'a-root-id', 'directory'),
+                          (u'a', 'a-id', 'file')], entries)
+        self.assertEqual('contents', rev_tree.get_file_text('a-id'))



More information about the bazaar-commits mailing list