Rev 3884: Change record_delete() to return the delta. in http://bzr.arbash-meinel.com/branches/bzr/1.11/add_inventory_by_delta

John Arbash Meinel john at arbash-meinel.com
Fri Dec 5 17:25:05 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.11/add_inventory_by_delta

------------------------------------------------------------
revno: 3884
revision-id: john at arbash-meinel.com-20081205172501-a0g7ho4sl29q6dz9
parent: john at arbash-meinel.com-20081205164010-05sx88jxi50q819a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: add_inventory_by_delta
timestamp: Fri 2008-12-05 11:25:01 -0600
message:
  Change record_delete() to return the delta.
  
  Add direct tests for CB.get_basis_delta(), to ensure that it returns a
  valid delta, and that it errors if the client hasn't called will_record_deletes.
-------------- next part --------------
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-12-05 16:29:05 +0000
+++ b/bzrlib/repository.py	2008-12-05 17:25:01 +0000
@@ -277,7 +277,9 @@
         """
         if not self._recording_deletes:
             raise AssertionError("recording deletes not activated.")
-        self._basis_delta.append((path, None, file_id, None))
+        delta = (path, None, file_id, None)
+        self._basis_delta.append(delta)
+        return delta
 
     def will_record_deletes(self):
         """Tell the commit builder that deletes are being notified.

=== modified file 'bzrlib/tests/per_repository/test_commit_builder.py'
--- a/bzrlib/tests/per_repository/test_commit_builder.py	2008-12-05 16:02:33 +0000
+++ b/bzrlib/tests/per_repository/test_commit_builder.py	2008-12-05 17:25:01 +0000
@@ -147,7 +147,7 @@
         parent_tree = tree.basis_tree()
         parent_tree.lock_read()
         self.addCleanup(parent_tree.unlock)
-        builder = tree.branch.get_commit_builder([parent_tree.inventory])
+        builder = tree.branch.get_commit_builder([old_revision_id])
         try:
             ie = inventory.make_entry('directory', '', None,
                     tree.get_root_id())
@@ -159,10 +159,9 @@
             # should be in the delta
             got_new_revision = ie.revision != old_revision_id
             if got_new_revision:
-                self.assertEqual(
-                    ('', '', ie.file_id, ie),
-                    delta)
-                self.assertEqual(delta, builder.basis_delta[-1])
+                self.assertEqual(('', '', ie.file_id, ie), delta)
+                # The delta should be tracked
+                self.assertEqual(delta, builder._basis_delta[-1])
             else:
                 self.assertEqual(None, delta)
             # Directories do not get hashed.
@@ -192,6 +191,63 @@
         # but thats all the current contract guarantees anyway.
         self.assertEqual(rev_id, tree.branch.repository.get_inventory(rev_id).revision_id)
 
+    def test_get_basis_delta(self):
+        tree = self.make_branch_and_tree(".")
+        self.build_tree(["foo"])
+        tree.add(["foo"], ["foo-id"])
+        old_revision_id = tree.commit("added foo")
+        tree.lock_write()
+        try:
+            self.build_tree(['bar'])
+            tree.add(['bar'], ['bar-id'])
+            basis = tree.branch.repository.revision_tree(old_revision_id)
+            basis.lock_read()
+            self.addCleanup(basis.unlock)
+            builder = tree.branch.get_commit_builder([old_revision_id])
+            total_delta = []
+            try:
+                parent_invs = [basis.inventory]
+                builder.will_record_deletes()
+                if builder.record_root_entry:
+                    ie = basis.inventory.root.copy()
+                    delta, _, _ = builder.record_entry_contents(ie, parent_invs,
+                        '', tree, tree.path_content_summary(''))
+                    if delta is not None:
+                        total_delta.append(delta)
+                delta = builder.record_delete("foo", "foo-id")
+                total_delta.append(delta)
+                new_bar = inventory.make_entry('file', 'bar',
+                    parent_id=tree.get_root_id(), file_id='bar-id')
+                delta, _, _ = builder.record_entry_contents(new_bar, parent_invs,
+                    'bar', tree, tree.path_content_summary('bar'))
+                total_delta.append(delta)
+                # All actions should have been recorded in the basis_delta
+                self.assertEqual(total_delta, builder.get_basis_delta())
+                builder.finish_inventory()
+                builder.commit('delete foo, add bar')
+            except:
+                tree.branch.repository.abort_write_group()
+                raise
+        finally:
+            tree.unlock()
+
+    def test_get_basis_delta_without_notification(self):
+        tree = self.make_branch_and_tree(".")
+        old_revision_id = tree.commit('')
+        tree.lock_write()
+        try:
+            parent_tree = tree.basis_tree()
+            parent_tree.lock_read()
+            self.addCleanup(parent_tree.unlock)
+            builder = tree.branch.get_commit_builder([old_revision_id])
+            # It is an error to expect builder.get_basis_delta() to be correct,
+            # if you have not also called will_record_deletes() to indicate you
+            # will be calling record_delete() when appropriate
+            self.assertRaises(AssertionError, builder.get_basis_delta)
+            tree.branch.repository.abort_write_group()
+        finally:
+            tree.unlock()
+
     def test_record_delete(self):
         tree = self.make_branch_and_tree(".")
         self.build_tree(["foo"])
@@ -205,15 +261,16 @@
             basis = tree.branch.repository.revision_tree(rev_id)
             builder = tree.branch.get_commit_builder([rev_id])
             try:
-                builder.recording_deletes()
+                builder.will_record_deletes()
                 if builder.record_root_entry is True:
                     parent_invs = [basis.inventory]
                     del basis.inventory.root.children['foo']
                     builder.record_entry_contents(basis.inventory.root,
                         parent_invs, '', tree, tree.path_content_summary(''))
-                builder.record_delete("foo", "foo-id")
-                self.assertEqual(("foo", None, "foo-id", None),
-                    builder.basis_delta[-1])
+                # the delta should be returned, and recorded in _basis_delta
+                delta = builder.record_delete("foo", "foo-id")
+                self.assertEqual(("foo", None, "foo-id", None), delta)
+                self.assertEqual(delta, builder._basis_delta[-1])
                 builder.finish_inventory()
                 rev_id2 = builder.commit('delete foo')
             except:
@@ -417,7 +474,7 @@
     def mini_commit(self, tree, name, new_name, records_version=True,
         delta_against_basis=True, expect_fs_hash=False):
         """Perform a miniature commit looking for record entry results.
-        
+
         :param tree: The tree to commit.
         :param name: The path in the basis tree of the tree being committed.
         :param new_name: The path in the tree being committed.
@@ -476,7 +533,8 @@
             new_entry = builder.new_inventory[file_id]
             if delta_against_basis:
                 expected_delta = (name, new_name, file_id, new_entry)
-                self.assertEqual(expected_delta, builder.basis_delta[-1])
+                # The delta should be recorded
+                self.assertEqual(expected_delta, builder._basis_delta[-1])
             else:
                 expected_delta = None
             self.assertEqual(expected_delta, delta)



More information about the bazaar-commits mailing list