92
95
>>> i = Inventory()
95
98
>>> i.add(InventoryDirectory(b'123', 'src', ROOT_ID))
96
InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
97
>>> i.add(InventoryFile(b'2323', 'hello.c', parent_id='123'))
98
InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None, revision=None)
99
InventoryDirectory(b'123', 'src', parent_id=b'TREE_ROOT', revision=None)
100
>>> i.add(InventoryFile(b'2323', 'hello.c', parent_id=b'123'))
101
InventoryFile(b'2323', 'hello.c', parent_id=b'123', sha1=None, len=None, revision=None)
99
102
>>> shouldbe = {0: '', 1: 'src', 2: 'src/hello.c'}
100
103
>>> for ix, j in enumerate(i.iter_entries()):
101
... print (j[0] == shouldbe[ix], j[1])
104
... print(j[0] == shouldbe[ix], j[1])
103
(True, InventoryDirectory('TREE_ROOT', u'', parent_id=None, revision=None))
104
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
105
(True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None, revision=None))
106
>>> i.add(InventoryFile('2324', 'bye.c', '123'))
107
InventoryFile('2324', 'bye.c', parent_id='123', sha1=None, len=None, revision=None)
108
>>> i.add(InventoryDirectory('2325', 'wibble', '123'))
109
InventoryDirectory('2325', 'wibble', parent_id='123', revision=None)
106
True InventoryDirectory(b'TREE_ROOT', '', parent_id=None, revision=None)
107
True InventoryDirectory(b'123', 'src', parent_id=b'TREE_ROOT', revision=None)
108
True InventoryFile(b'2323', 'hello.c', parent_id=b'123', sha1=None, len=None, revision=None)
109
>>> i.add(InventoryFile(b'2324', 'bye.c', b'123'))
110
InventoryFile(b'2324', 'bye.c', parent_id=b'123', sha1=None, len=None, revision=None)
111
>>> i.add(InventoryDirectory(b'2325', 'wibble', b'123'))
112
InventoryDirectory(b'2325', 'wibble', parent_id=b'123', revision=None)
110
113
>>> i.path2id('src/wibble')
112
>>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
113
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None, revision=None)
114
>>> i.get_entry('2326')
115
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None, revision=None)
115
>>> i.add(InventoryFile(b'2326', 'wibble.c', b'2325'))
116
InventoryFile(b'2326', 'wibble.c', parent_id=b'2325', sha1=None, len=None, revision=None)
117
>>> i.get_entry(b'2326')
118
InventoryFile(b'2326', 'wibble.c', parent_id=b'2325', sha1=None, len=None, revision=None)
116
119
>>> for path, entry in i.iter_entries():
1001
1003
>>> inv = Inventory()
1002
1004
>>> inv.add(InventoryFile(b'123-123', 'hello.c', ROOT_ID))
1003
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
1005
InventoryFile(b'123-123', 'hello.c', parent_id=b'TREE_ROOT', sha1=None, len=None, revision=None)
1004
1006
>>> inv.get_entry(b'123-123').name
1007
1009
Id's may be looked up from paths:
1009
1011
>>> inv.path2id('hello.c')
1011
1013
>>> inv.has_id(b'123-123')
1014
1016
There are iterators over the contents:
1016
1018
>>> [entry[0] for entry in inv.iter_entries()]
1020
1022
def __init__(self, root_id=ROOT_ID, revision_id=None):
1301
1303
>>> i1.add(InventoryFile(b'123', 'foo', ROOT_ID))
1302
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
1304
InventoryFile(b'123', 'foo', parent_id=b'TREE_ROOT', sha1=None, len=None, revision=None)
1305
1307
>>> i2.add(InventoryFile(b'123', 'foo', ROOT_ID))
1306
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
1308
InventoryFile(b'123', 'foo', parent_id=b'TREE_ROOT', sha1=None, len=None, revision=None)
1855
1857
raise errors.BzrError('Duplicate key in inventory: %r\n%r'
1856
1858
% (key, bytes))
1857
1859
info[key] = value
1858
revision_id = bytesintern(info[b'revision_id'])
1859
root_id = bytesintern(info[b'root_id'])
1860
search_key_name = bytesintern(info.get(b'search_key_name', b'plain'))
1861
parent_id_basename_to_file_id = bytesintern(info.get(
1862
b'parent_id_basename_to_file_id', None))
1860
revision_id = info[b'revision_id']
1861
root_id = info[b'root_id']
1862
search_key_name = info.get(b'search_key_name', b'plain')
1863
parent_id_basename_to_file_id = info.get(
1864
b'parent_id_basename_to_file_id', None)
1863
1865
if not parent_id_basename_to_file_id.startswith(b'sha1:'):
1864
1866
raise ValueError('parent_id_basename_to_file_id should be a sha1'
1865
1867
' key not %r' % (parent_id_basename_to_file_id,))