Rev 4513: Fix fallout from the delta checking work, don't error on deltas containing the root inventory item in CHK delta application, and clean up Inventory docs. in http://bazaar.launchpad.net/~lifeless/bzr/apply-inventory-delta
Robert Collins
robertc at robertcollins.net
Fri Jul 10 06:18:35 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/apply-inventory-delta
------------------------------------------------------------
revno: 4513
revision-id: robertc at robertcollins.net-20090710051829-zesmf7tf2jwohfip
parent: robertc at robertcollins.net-20090710023346-hkohwlngffgw71z1
committer: Robert Collins <robertc at robertcollins.net>
branch nick: apply-inventory-delta
timestamp: Fri 2009-07-10 15:18:29 +1000
message:
Fix fallout from the delta checking work, don't error on deltas containing the root inventory item in CHK delta application, and clean up Inventory docs.
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2009-07-10 02:33:46 +0000
+++ b/bzrlib/dirstate.py 2009-07-10 05:18:29 +0000
@@ -1459,9 +1459,6 @@
(source_path, target_path, entry[0][2], None, False))
deletes.append(
(encode(old_path), new_path, file_id, None, False))
- # note the parent for validation
- dirname, basename = osutils.split(new_path)
- parents.add((dirname, inv_entry.parent_id))
else:
# changes to just the root should not require remove/insertion
# of everything.
@@ -1609,12 +1606,12 @@
entry = self._get_entry(1, file_id, dirname)
if entry[1] is None:
self._changes_aborted = True
- raise errors.InconsistentDelta(dirname, file_id,
+ raise errors.InconsistentDelta(dirname.decode('utf8'), file_id,
"This parent is not present.")
# Parents of things must be directories
if entry[1][1][0] != 'd':
self._changes_aborted = True
- raise errors.InconsistentDelta(dirname, file_id,
+ raise errors.InconsistentDelta(dirname.decode('utf8'), file_id,
"This parent is not a directory.")
def _observed_sha1(self, entry, sha1, stat_value,
@@ -1865,7 +1862,7 @@
self._read_dirblocks_if_needed()
if path_utf8 is not None:
if type(path_utf8) is not str:
- raise AssertionError('path_utf8 is not a str: %s %s'
+ raise errors.BzrError('path_utf8 is not a str: %s %r'
% (type(path_utf8), path_utf8))
# path lookups are faster
dirname, basename = osutils.split(path_utf8)
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2009-07-09 23:04:39 +0000
+++ b/bzrlib/inventory.py 2009-07-10 05:18:29 +0000
@@ -712,7 +712,19 @@
class CommonInventory(object):
- """Basic inventory logic, defined in terms of primitives like has_id."""
+ """Basic inventory logic, defined in terms of primitives like has_id.
+
+ An inventory is the metadata about the contents of a tree.
+
+ This is broadly a map from file_id to entries such as directories, files,
+ symlinks and tree references. Each entry maintains its own metadata like
+ SHA1 and length for files, or children for a directory.
+
+ Entries can be looked up either by path or by file_id.
+
+ InventoryEntry objects must not be modified after they are
+ inserted, other than through the Inventory API.
+ """
def __contains__(self, file_id):
"""True if this entry contains a file with given id.
@@ -1019,46 +1031,32 @@
class Inventory(CommonInventory):
- """Inventory of versioned files in a tree.
-
- This describes which file_id is present at each point in the tree,
- and possibly the SHA-1 or other information about the file.
- Entries can be looked up either by path or by file_id.
-
- The inventory represents a typical unix file tree, with
- directories containing files and subdirectories. We never store
- the full path to a file, because renaming a directory implicitly
- moves all of its contents. This class internally maintains a
+ """Mutable dict based in-memory inventory.
+
+ We never store the full path to a file, because renaming a directory
+ implicitly moves all of its contents. This class internally maintains a
lookup tree that allows the children under a directory to be
returned quickly.
- InventoryEntry objects must not be modified after they are
- inserted, other than through the Inventory API.
-
>>> inv = Inventory()
>>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
>>> inv['123-123'].name
'hello.c'
- May be treated as an iterator or set to look up file ids:
+ Id's may be looked up from paths:
- >>> bool(inv.path2id('hello.c'))
- True
+ >>> inv.path2id('hello.c')
+ '123-123'
>>> '123-123' in inv
True
- May also look up by name:
+ There are iterators over the contents:
- >>> [x[0] for x in inv.iter_entries()]
+ >>> [entry[0] for entry in inv.iter_entries()]
['', u'hello.c']
- >>> inv = Inventory('TREE_ROOT-12345678-12345678')
- >>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
- Traceback (most recent call last):
- BzrError: parent_id {TREE_ROOT} not in inventory
- >>> inv.add(InventoryFile('123-123', 'hello.c', 'TREE_ROOT-12345678-12345678'))
- InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678', sha1=None, len=None, revision=None)
"""
+
def __init__(self, root_id=ROOT_ID, revision_id=None):
"""Create or read an inventory.
@@ -1680,6 +1678,7 @@
result.id_to_entry.apply_delta(id_to_entry_delta)
if parent_id_basename_delta:
result.parent_id_basename_to_file_id.apply_delta(parent_id_basename_delta)
+ parents.discard(None)
for parent in parents:
try:
if result[parent].kind != 'directory':
=== modified file 'bzrlib/tests/inventory_implementations/basics.py'
--- a/bzrlib/tests/inventory_implementations/basics.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/inventory_implementations/basics.py 2009-07-10 05:18:29 +0000
@@ -112,12 +112,9 @@
def test_error_encoding(self):
inv = self.make_inventory('tree-root')
inv.add(InventoryFile('a-id', u'\u1234', 'tree-root'))
- try:
- inv.add(InventoryFile('b-id', u'\u1234', 'tree-root'))
- except errors.BzrError, e:
- self.assertContainsRe(str(e), u'\u1234'.encode('utf-8'))
- else:
- self.fail('BzrError not raised')
+ e = self.assertRaises(errors.InconsistentDelta, inv.add,
+ InventoryFile('b-id', u'\u1234', 'tree-root'))
+ self.assertContainsRe(str(e), r'\\u1234')
def test_add_recursive(self):
parent = InventoryDirectory('src-id', 'src', 'tree-root')
@@ -129,6 +126,13 @@
class TestInventoryApplyDelta(TestInventory):
+ """A subset of the inventory delta application tests.
+
+ See test_inv which has comprehensive delta application tests for
+ inventories, dirstate, and repository based inventories, unlike the tests
+ here which only test in-memory implementations that can support a plain
+ 'apply_delta'.
+ """
def test_apply_delta_add(self):
inv = self.make_inventory('tree-root')
@@ -161,7 +165,7 @@
def test_apply_delta_illegal(self):
# A file-id cannot appear in a delta more than once
inv = self.make_inventory('tree-root')
- self.assertRaises(AssertionError, inv.apply_delta, [
+ self.assertRaises(errors.InconsistentDelta, inv.apply_delta, [
("a", "a", "id-1", InventoryFile('id-1', 'a', 'tree-root')),
("a", "b", "id-1", InventoryFile('id-1', 'b', 'tree-root')),
])
More information about the bazaar-commits
mailing list