Rev 4511: Check for missing parents in deltas. in http://people.ubuntu.com/~robertc/baz2.0/pending/apply-inventory-delta

Robert Collins robertc at robertcollins.net
Fri Jul 10 00:04:52 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/apply-inventory-delta

------------------------------------------------------------
revno: 4511
revision-id: robertc at robertcollins.net-20090709230439-vztby1svjthvodkv
parent: robertc at robertcollins.net-20090709053225-xzyadu36hda1w0az
committer: Robert Collins <robertc at robertcollins.net>
branch nick: apply-inventory-delta
timestamp: Fri 2009-07-10 09:04:39 +1000
message:
  Check for missing parents in deltas.
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2009-07-09 05:32:25 +0000
+++ b/bzrlib/dirstate.py	2009-07-09 23:04:39 +0000
@@ -1605,6 +1605,10 @@
             # Get the entry - the ensures that file_id, dirname exists and has
             # the right file id.
             entry = self._get_entry(1, file_id, dirname)
+            if entry[1] is None:
+                self._changes_aborted = True
+                raise errors.InconsistentDelta(dirname, file_id,
+                    "This parent is not present.")
             # Parents of things must be directories
             if entry[1][1][0] != 'd':
                 self._changes_aborted = True

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-07-09 05:32:25 +0000
+++ b/bzrlib/inventory.py	2009-07-09 23:04:39 +0000
@@ -1268,9 +1268,8 @@
             try:
                 parent = self._byid[entry.parent_id]
             except KeyError:
-                raise BzrError("parent_id {%s} not in inventory" %
-                               entry.parent_id)
-
+                raise errors.InconsistentDelta("<unknown>", entry.parent_id,
+                    "Parent not in inventory.")
             if entry.name in parent.children:
                 raise errors.InconsistentDelta(
                     self.id2path(parent.children[entry.name].file_id),
@@ -1682,9 +1681,13 @@
         if parent_id_basename_delta:
             result.parent_id_basename_to_file_id.apply_delta(parent_id_basename_delta)
         for parent in parents:
-            if result[parent].kind != 'directory':
-                raise errors.InconsistentDelta(result.id2path(parent), parent,
-                    'Not a directory, but given children')
+            try:
+                if result[parent].kind != 'directory':
+                    raise errors.InconsistentDelta(result.id2path(parent), parent,
+                        'Not a directory, but given children')
+            except errors.NoSuchId:
+                raise errors.InconsistentDelta("<unknown>", parent,
+                    "Parent is not present in resulting inventory.")
         return result
 
     @classmethod

=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py	2009-07-09 05:32:25 +0000
+++ b/bzrlib/tests/test_inv.py	2009-07-09 23:04:39 +0000
@@ -125,9 +125,11 @@
         parents = osutils.minimum_path_selection(parents)
         parents.discard('')
         # Put place holders in the tree to permit adding the other entries.
-        for parent in parents:
+        for pos, parent in enumerate(parents):
             if not tree.path2id(parent):
-                import pdb;pdb.set_trace()
+                # add a synthetic directory in the tree so we can can put the
+                # tree0 entries in place for dirstate.
+                tree.add([parent], ["id%d" % pos], ["directory"])
         if paths:
             # Many deltas may cause this mini-apply to fail, but we want to see what
             # the delta application code says, not the prep that we do to deal with 
@@ -309,6 +311,16 @@
         self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
             inv, delta)
 
+    def test_parent_is_missing(self):
+        inv = self.get_empty_inventory()
+        file2 = inventory.InventoryFile('id2', 'path2', 'missingparent')
+        file2.revision = 'result'
+        file2.text_size = 0
+        file2.text_sha1 = ""
+        delta = [(None, 'path/path2', 'id2', file2)]
+        self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
+            inv, delta)
+
 
 class TestInventoryEntry(TestCase):
 




More information about the bazaar-commits mailing list