b.i.Inventory(CommonInventory) : class documentation

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.
def __init__(self, root_id=ROOT_ID, revision_id=None):
Create or read an inventory.

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.

def __repr__(self):
Undocumented
def apply_delta(self, delta):
Apply a delta to this inventory.

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.

ParametersdeltaA 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.

def create_by_apply_delta(self, inventory_delta, new_revision_id, propagate_caches=False):
See CHKInventory.create_by_apply_delta()
def _set_root(self, ie):
Undocumented
def copy(self):
Undocumented
def __iter__(self):
Iterate over all file-ids.
def iter_just_entries(self):
Iterate over all entries.

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.

def __len__(self):
Returns number of entries.
def __getitem__(self, file_id):

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'
def get_file_kind(self, file_id):
Undocumented
def get_child(self, parent_id, filename):
Undocumented
def _add_child(self, entry):
Add an entry to the inventory, without adding it to its parent
def add(self, entry):
Add entry to inventory.
Returnsentry
def add_path(self, relpath, kind, file_id=None, parent_id=None):
Add entry from a path.

The immediate parent must already be versioned.

Returns the new entry object.

def __delitem__(self, file_id):

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
def __eq__(self, other):

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
def __ne__(self, other):
Undocumented
def __hash__(self):
Undocumented
def _iter_file_id_parents(self, file_id):
Yield the parents of file_id up to the root.
def has_id(self, file_id):
Undocumented
def _make_delta(self, old):
Make an inventory delta from two inventories.
def remove_recursive_id(self, file_id):
Remove file_id, and children, from the inventory.
Parametersfile_idA file_id to remove.
def rename(self, file_id, new_parent_id, new_name):
Move a file within the inventory.

This can change either the name, or the parent, or both.

This does not move the working file.

def is_root(self, file_id):
Undocumented
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.