Part of bzrlib.inventory View In Hierarchy
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.
>>> 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'
Id's may be looked up from paths:
>>> inv.path2id('hello.c') '123-123' >>> inv.has_id('123-123') True
There are iterators over the contents:
>>> [entry[0] for entry in inv.iter_entries()] ['', u'hello.c']
Method | __init__ | Create or read an inventory. |
Method | __repr__ | Undocumented |
Method | apply_delta | Apply a delta to this inventory. |
Method | create_by_apply_delta | See CHKInventory.create_by_apply_delta() |
Method | copy | Undocumented |
Method | __iter__ | Iterate over all file-ids. |
Method | iter_just_entries | Iterate over all entries. |
Method | __len__ | Returns number of entries. |
Method | __getitem__ | Return the entry for given file_id. |
Method | get_file_kind | Undocumented |
Method | get_child | Undocumented |
Method | add | Add entry to inventory. |
Method | add_path | Add entry from a path. |
Method | __delitem__ | Remove entry by id. |
Method | __eq__ | Compare two sets by comparing their contents. |
Method | __ne__ | Undocumented |
Method | __hash__ | Undocumented |
Method | has_id | Undocumented |
Method | remove_recursive_id | Remove file_id, and children, from the inventory. |
Method | rename | Move a file within the inventory. |
Method | is_root | Undocumented |
Method | _set_root | Undocumented |
Method | _add_child | Add an entry to the inventory, without adding it to its parent |
Method | _iter_file_id_parents | Yield the parents of file_id up to the root. |
Method | _make_delta | Make an inventory delta from two inventories. |
Inherited from CommonInventory:
Method | __contains__ | True if this entry contains a file with given id. |
Method | has_filename | Undocumented |
Method | id2path | Return as a string the path to file_id. |
Method | iter_entries | Return (path, entry) pairs, in order by name. |
Method | iter_entries_by_dir | Iterate over the entries in a directory first order. |
Method | make_entry | Simple thunk to bzrlib.inventory.make_entry. |
Method | entries | Return list of (path, ie) for all entries except the root. |
Method | directories | Return (path, entry) pairs for all directories, including the root. |
Method | path2id | Walk down through directories to return entry of last component. |
Method | filter | Get an inventory view filtered against a set of file-ids. |
Method | get_idpath | Return a list of file_ids for the path to an entry. |
Method | _preload_cache | Populate any caches, we are about to access all items. |
If a working directory is specified, the inventory is read from there. If the file is specified, read from that. If not, the inventory is created empty.
The inventory is created with a default root directory, with an id of None.
See the inventory developers documentation for the theory behind inventory deltas.
If delta application fails the inventory is left in an indeterminate state and must not be used.
Parameters | delta | A list of changes to apply. After all the changes are
applied the final inventory must be internally consistent, but it
is ok to supply changes which, if only half-applied would have an
invalid result - such as supplying two changes which rename two
files, 'A' and 'B' with each other : [('A', 'B', 'A-id', a_entry),
('B', 'A', 'B-id', b_entry)].
Each change is a tuple, of the form (old_path, new_path, file_id, new_entry). When new_path is None, the change indicates the removal of an entry from the inventory and new_entry will be ignored (using None is appropriate). If new_path is not None, then new_entry must be an InventoryEntry instance, which will be incorporated into the inventory (and replace any existing entry with the same file id). When old_path is None, the change indicates the addition of a new entry to the inventory. When neither new_path nor old_path are None, the change is a modification to an entry, such as a rename, reparent, kind change etc. The children attribute of new_entry is ignored. This is because this method preserves children automatically across alterations to the parent of the children, and cases where the parent id of a child is changing require the child to be passed in as a separate change regardless. E.g. in the recursive deletion of a directory - the directory's children must be included in the delta, or the final inventory will be invalid. Note that a file_id must only appear once within a given delta. An AssertionError is raised otherwise. |
Unlike iter_entries(), just the entries are returned (not (path, ie)) and the order of entries is undefined.
XXX: We may not want to merge this into bzr.dev.
Return the entry for given file_id.
>>> inv = Inventory() >>> inv.add(InventoryFile('123123', 'hello.c', ROOT_ID)) InventoryFile('123123', 'hello.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None) >>> inv['123123'].name 'hello.c'
The immediate parent must already be versioned.
Returns the new entry object.
Remove entry by id.
>>> inv = Inventory() >>> inv.add(InventoryFile('123', 'foo.c', ROOT_ID)) InventoryFile('123', 'foo.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None) >>> inv.has_id('123') True >>> del inv['123'] >>> inv.has_id('123') False
Compare two sets by comparing their contents.
>>> i1 = Inventory() >>> i2 = Inventory() >>> i1 == i2 True >>> i1.add(InventoryFile('123', 'foo', ROOT_ID)) InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None, revision=None) >>> i1 == i2 False >>> i2.add(InventoryFile('123', 'foo', ROOT_ID)) InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None, revision=None) >>> i1 == i2 True
Parameters | file_id | A file_id to remove. |