Rev 4530: Look for trivial issues with new_path and entry being out of sync in deltas. in http://bazaar.launchpad.net/~lifeless/bzr/apply-inventory-delta
Robert Collins
robertc at robertcollins.net
Mon Jul 13 06:44:09 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/apply-inventory-delta
------------------------------------------------------------
revno: 4530
revision-id: robertc at robertcollins.net-20090713054406-py4vt6uns5yyoya0
parent: robertc at robertcollins.net-20090713045134-wwr4zgl1bne4ay66
committer: Robert Collins <robertc at robertcollins.net>
branch nick: apply-inventory-delta
timestamp: Mon 2009-07-13 15:44:06 +1000
message:
Look for trivial issues with new_path and entry being out of sync in deltas.
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2009-07-13 04:51:34 +0000
+++ b/bzrlib/dirstate.py 2009-07-13 05:44:06 +0000
@@ -1296,7 +1296,9 @@
for old_path, new_path, file_id, inv_entry in sorted(
inventory._check_delta_unique_old_paths(
inventory._check_delta_unique_new_paths(
- inventory._check_delta_ids_match_entry(delta))), reverse=True):
+ inventory._check_delta_ids_match_entry(
+ inventory._check_delta_new_path_entry_both_or_None(delta)))),
+ reverse=True):
if (file_id in insertions) or (file_id in removals):
self._changes_aborted = True
raise errors.InconsistentDelta(old_path or new_path, file_id,
@@ -1305,6 +1307,9 @@
old_path = old_path.encode('utf-8')
removals[file_id] = old_path
if new_path is not None:
+ if inv_entry is None:
+ raise errors.InconsistentDelta(new_path, file_id,
+ "new_path with no entry")
new_path = new_path.encode('utf-8')
dirname, basename = osutils.split(new_path)
dirname_utf8 = encode(dirname)
@@ -1454,6 +1459,9 @@
raise errors.InconsistentDelta(new_path, file_id,
"mismatched entry file_id %r" % inv_entry)
if new_path is not None:
+ if inv_entry is None:
+ raise errors.InconsistentDelta(new_path, file_id,
+ "new_path with no entry")
new_path_utf8 = encode(new_path)
# note the parent for validation
dirname_utf8, basename_utf8 = osutils.split(new_path_utf8)
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2009-07-13 04:51:34 +0000
+++ b/bzrlib/inventory.py 2009-07-13 05:44:06 +0000
@@ -1132,7 +1132,8 @@
# facility.
list(_check_delta_unique_ids(_check_delta_unique_new_paths(
_check_delta_unique_old_paths(_check_delta_ids_match_entry(
- delta)))))
+ _check_delta_new_path_entry_both_or_None(
+ delta))))))
children = {}
# Remove all affected items which were in the original inventory,
@@ -1156,7 +1157,7 @@
# longest, ensuring that items which were modified and whose parents in
# the resulting inventory were also modified, are inserted after their
# parents.
- for new_path, new_entry in sorted((np, e) for op, np, f, e in
+ for new_path, f, new_entry in sorted((np, f, e) for op, np, f, e in
delta if np is not None):
if new_entry.kind == 'directory':
# Pop the child which to allow detection of children whose
@@ -1636,6 +1637,9 @@
inventory_delta = _check_delta_unique_new_paths(inventory_delta)
# Check for entries that don't match the fileid
inventory_delta = _check_delta_ids_match_entry(inventory_delta)
+ # Check for new_path <-> entry consistency
+ inventory_delta = _check_delta_new_path_entry_both_or_None(
+ inventory_delta)
# All changed entries need to have their parents be directories and be
# at the right path. This set contains (path, id) tuples.
parents = set()
@@ -2170,3 +2174,20 @@
raise errors.InconsistentDelta(item[0] or item[1], item[2],
"mismatched id with %r" % entry)
yield item
+
+
+def _check_delta_new_path_entry_both_or_None(delta):
+ """Decorate a delta and check that the new_path and entry are paired.
+
+ :return: A generator over delta.
+ """
+ for item in delta:
+ new_path = item[1]
+ entry = item[3]
+ if new_path is None and entry is not None:
+ raise errors.InconsistentDelta(item[0], item[1],
+ "Entry with no new_path")
+ if new_path is not None and entry is None:
+ raise errors.InconsistentDelta(new_path, item[1],
+ "new_path with no entry")
+ yield item
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2009-07-13 04:51:34 +0000
+++ b/bzrlib/tests/test_inv.py 2009-07-13 05:44:06 +0000
@@ -159,7 +159,7 @@
paths = {}
parents = set()
for old, new, id, entry in delta:
- if entry is None:
+ if None in (new, entry):
continue
paths[new] = (entry.file_id, entry.kind)
parents.add(osutils.dirname(new))
@@ -337,6 +337,22 @@
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
inv, delta)
+ def test_mismatched_new_path_entry_None(self):
+ inv = self.get_empty_inventory()
+ delta = [(None, u'path', 'id', None)]
+ self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
+ inv, delta)
+
+ def test_mismatched_new_path_None_entry(self):
+ inv = self.get_empty_inventory()
+ file1 = inventory.InventoryFile('id1', 'path', inv.root.file_id)
+ file1.revision = 'result'
+ file1.text_size = 0
+ file1.text_sha1 = ""
+ delta = [(u"path", None, 'id1', file1)]
+ self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
+ inv, delta)
+
def test_parent_is_not_directory(self):
inv = self.get_empty_inventory()
file1 = inventory.InventoryFile('id1', 'path', inv.root.file_id)
More information about the bazaar-commits
mailing list