Rev 3587: Cause apply_inventory_delta on Inventory objects to fail with deltas that leave dangling children. in http://people.ubuntu.com/~robertc/baz2.0/150438

Robert Collins robertc at robertcollins.net
Wed Jul 30 09:20:25 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/150438

------------------------------------------------------------
revno: 3587
revision-id: robertc at robertcollins.net-20080730082020-vff6erv12li5x0en
parent: robertc at robertcollins.net-20080730075222-azbmg0knc7u9mkpg
committer: Robert Collins <robertc at robertcollins.net>
branch nick: 150438
timestamp: Wed 2008-07-30 18:20:20 +1000
message:
  Cause apply_inventory_delta on Inventory objects to fail with deltas that leave dangling children.
modified:
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2008-06-19 13:14:24 +0000
+++ b/bzrlib/inventory.py	2008-07-30 08:20:20 +0000
@@ -813,7 +813,9 @@
                 # adds come later
                 continue
             # Preserve unaltered children of file_id for later reinsertion.
-            children[file_id] = getattr(self[file_id], 'children', {})
+            file_id_children = getattr(self[file_id], 'children', {})
+            if len(file_id_children):
+                children[file_id] = file_id_children
             # Remove file_id and the unaltered children. If file_id is not
             # being deleted it will be reinserted back later.
             self.remove_recursive_id(file_id)
@@ -825,8 +827,16 @@
         for new_path, new_entry in sorted((np, e) for op, np, f, e in
                                           delta if np is not None):
             if new_entry.kind == 'directory':
-                new_entry.children = children.get(new_entry.file_id, {})
+                # Pop the child which to allow detection of children whose
+                # parents were deleted and which were not reattached to a new
+                # parent.
+                new_entry.children = children.pop(new_entry.file_id, {})
             self.add(new_entry)
+        if len(children):
+            # Get the parent id that was deleted
+            parent_id, children = children.popitem()
+            raise errors.InconsistentDelta("<deleted>", parent_id,
+                "The file id was deleted but its children were not deleted.")
 
     def _set_root(self, ie):
         self.root = ie




More information about the bazaar-commits mailing list