b.i.CommonInventory(object) : class documentation

Part of bzrlib.inventory View In Hierarchy

Known subclasses: bzrlib.inventory.CHKInventory, bzrlib.inventory.Inventory

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.

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.
Method _make_delta Make an inventory delta from two inventories.
@deprecated_method(deprecated_in((2, 4, 0)))
def __contains__(self, file_id):
True if this entry contains a file with given 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
>>> inv.has_id('456')
False

Note that this method along with __iter__ are not encouraged for use as they are less clear than specific query methods - they may be rmeoved in the future.

def has_filename(self, filename):
Undocumented
def id2path(self, file_id):

Return as a string the path to file_id.

>>> i = Inventory()
>>> e = i.add(InventoryDirectory('src-id', 'src', ROOT_ID))
>>> e = i.add(InventoryFile('foo-id', 'foo.c', parent_id='src-id'))
>>> print i.id2path('foo-id')
src/foo.c
RaisesNoSuchIdIf file_id is not present in the inventory.
def iter_entries(self, from_dir=None, recursive=True):
Return (path, entry) pairs, in order by name.
Parametersfrom_dirif None, start from the root, otherwise start from this directory (either file-id or entry)
recursiverecurse into directories or not
def _preload_cache(self):
Populate any caches, we are about to access all items.

The default implementation does nothing, because CommonInventory doesn't have a cache.

def iter_entries_by_dir(self, from_dir=None, specific_file_ids=None, yield_parents=False):
Iterate over the entries in a directory first order.

This returns all entries for a directory before returning the entries for children of a directory. This is not lexicographically sorted order, and is a hybrid between depth-first and breadth-first.

Parametersyield_parentsIf True, yield the parents from the root leading down to specific_file_ids that have been requested. This has no impact if specific_file_ids is None.
ReturnsThis yields (path, entry) pairs
def _make_delta(self, old):
Make an inventory delta from two inventories.
def make_entry(self, kind, name, parent_id, file_id=None):
Simple thunk to bzrlib.inventory.make_entry.
def entries(self):
Return list of (path, ie) for all entries except the root.

This may be faster than iter_entries.

def directories(self):
Return (path, entry) pairs for all directories, including the root.
def path2id(self, relpath):
Walk down through directories to return entry of last component.

This returns the entry of the last component in the path, which may be either a file or a directory.

Returns None IFF the path is not found.

Parametersrelpathmay be either a list of path components, or a single string, in which case it is automatically split.
def filter(self, specific_fileids):
Get an inventory view filtered against a set of file-ids.

Children of directories and parents are included.

The result may or may not reference the underlying inventory so it should be treated as immutable.

def get_idpath(self, file_id):
Return a list of file_ids for the path to an entry.

The list contains one element for each directory followed by the id of the file itself. So the length of the returned list is equal to the depth of the file in the tree, counting the root directory as depth 1.

API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.