79
79
>>> i.add(InventoryDirectory('123', 'src', ROOT_ID))
80
InventoryDirectory('123', 'src', parent_id='TREE_ROOT')
80
InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
81
81
>>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
82
InventoryFile('2323', 'hello.c', parent_id='123')
82
InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None)
83
83
>>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
84
84
>>> for ix, j in enumerate(i.iter_entries()):
85
85
... print (j[0] == shouldbe[ix], j[1])
87
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
88
(True, InventoryFile('2323', 'hello.c', parent_id='123'))
87
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
88
(True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None))
89
89
>>> i.add(InventoryFile('2323', 'bye.c', '123'))
90
90
Traceback (most recent call last):
92
92
BzrError: inventory already contains entry with id {2323}
93
93
>>> i.add(InventoryFile('2324', 'bye.c', '123'))
94
InventoryFile('2324', 'bye.c', parent_id='123')
94
InventoryFile('2324', 'bye.c', parent_id='123', sha1=None, len=None)
95
95
>>> i.add(InventoryDirectory('2325', 'wibble', '123'))
96
InventoryDirectory('2325', 'wibble', parent_id='123')
96
InventoryDirectory('2325', 'wibble', parent_id='123', revision=None)
97
97
>>> i.path2id('src/wibble')
101
101
>>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
102
InventoryFile('2326', 'wibble.c', parent_id='2325')
102
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
104
InventoryFile('2326', 'wibble.c', parent_id='2325')
104
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
105
105
>>> for path, entry in i.iter_entries():
107
107
... assert i.path2id(path)
393
393
return 'unchanged'
395
395
def __repr__(self):
396
return ("%s(%r, %r, parent_id=%r)"
396
return ("%s(%r, %r, parent_id=%r, revision=%r)"
397
397
% (self.__class__.__name__,
402
403
def snapshot(self, revision, path, previous_entries,
403
404
work_tree, commit_builder):
833
844
>>> inv = Inventory('TREE_ROOT-12345678-12345678')
834
845
>>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
835
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678')
846
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678', sha1=None, len=None)
837
848
def __init__(self, root_id=ROOT_ID, revision_id=None):
838
849
"""Create or read an inventory.
1096
1109
>>> i1.add(InventoryFile('123', 'foo', ROOT_ID))
1097
InventoryFile('123', 'foo', parent_id='TREE_ROOT')
1110
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None)
1100
1113
>>> i2.add(InventoryFile('123', 'foo', ROOT_ID))
1101
InventoryFile('123', 'foo', parent_id='TREE_ROOT')
1114
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None)
1105
1118
if not isinstance(other, Inventory):
1106
1119
return NotImplemented
1108
if len(self._byid) != len(other._byid):
1109
# shortcut: obviously not the same
1112
1121
return self._byid == other._byid
1114
1123
def __ne__(self, other):