b.t.TreeTransformBase(object) : class documentation

Part of bzrlib.transform View In Hierarchy

Known subclasses: bzrlib.transform.DiskTreeTransform

The base class for TreeTransform and its kin.
Method __init__ Constructor.
Method __enter__ Support Context Manager API.
Method __exit__ Support Context Manager API.
Method finalize Release the working tree lock, if held.
Method create_path Assign a transaction id to a new path
Method adjust_path Change the path that is assigned to a transaction id.
Method adjust_root_path Emulate moving the root by moving all children, instead.
Method fixup_new_roots Reinterpret requests to change the root directory
Method trans_id_tree_file_id Determine the transaction id of a working tree file.
Method trans_id_file_id Determine or set the transaction id associated with a file ID.
Method trans_id_tree_path Determine (and maybe set) the transaction ID for a tree path.
Method get_tree_parent Determine id of the parent in the tree.
Method delete_contents Schedule the contents of a path entry for deletion
Method cancel_deletion Cancel a scheduled deletion
Method unversion_file Schedule a path entry to become unversioned
Method delete_versioned Delete and unversion a versioned file
Method set_executability Schedule setting of the 'execute' bit
Method set_tree_reference Set the reference associated with a directory
Method version_file Schedule a file to become versioned.
Method cancel_versioning Undo a previous versioning of a file
Method new_paths Determine the paths of all new and changed files.
Method final_kind Determine the final file kind, after any changes applied.
Method tree_file_id Determine the file id associated with the trans_id in the tree
Method final_file_id Determine the file id after any changes are applied, or None.
Method inactive_file_id Return the inactive file_id associated with a transaction id.
Method final_parent Determine the parent file_id, after any changes are applied.
Method final_name Determine the final filename, after all changes are applied.
Method by_parent Return a map of parent: children for known parents.
Method path_changed Return True if a trans_id's path has changed.
Method new_contents Undocumented
Method find_conflicts Find any violations of inventory or filesystem invariants
Method has_named_child Undocumented
Method new_file Convenience method to create files.
Method new_directory Convenience method to create directories.
Method new_symlink Convenience method to create symbolic link.
Method new_orphan Schedule an item to be orphaned.
Method iter_changes Produce output in the same format as Tree.iter_changes.
Method get_preview_tree Return a tree representing the result of the transform.
Method commit Commit the result of this TreeTransform to a branch.
Method serialize Serialize this TreeTransform.
Method deserialize Deserialize a stored TreeTransform.
Method __get_root Undocumented
Method _assign_id Produce a new tranform id
Method _inventory_altered Determine which trans_ids need new Inventory entries.
Method _check_malformed Undocumented
Method _add_tree_children Add all the children of all active parents to the known paths.
Method _has_named_child Does a parent already have a name child.
Method _available_backup_name Find an available backup name.
Method _parent_loops No entry should be its own ancestor
Method _unversioned_parents If parent directories are versioned, children must be versioned.
Method _improper_versioning Cannot version a file with no contents, or a bad type.
Method _executability_conflicts Check for bad executability changes.
Method _overwrite_conflicts Check for overwrites (not permitted on Win32)
Method _duplicate_entries No directory may have two entries with the same name.
Method _duplicate_ids Each inventory id may only be used once
Method _parent_type_conflicts Children must have a directory parent
Method _set_executability Set the executability of versioned files
Method _new_entry Helper function to create a new filesystem entry.
Method _get_potential_orphans Find the potential orphans in a directory.
Method _affected_ids Return the set of transform ids affected by the transform
Method _get_file_id_maps Return mapping of file_ids to trans_ids in the to and from states
Method _from_file_data Get data about a file in the from (tree) state
Method _to_file_data Get data about a file in the to (target) state
Method _text_parent Undocumented
Method _get_parents_texts Get texts for compression parents of this file.
Method _get_parents_lines Get lines for compression parents of this file.
def __init__(self, tree, pb=None, case_sensitive=True):
Constructor.
ParameterstreeThe tree that will be transformed, but not necessarily the output tree.
pbignored
case_sensitiveIf True, the target of the transform is case sensitive, not just case preserving.
def __enter__(self):
Support Context Manager API.
def __exit__(self, exc_type, exc_val, exc_tb):
Support Context Manager API.
def finalize(self):
Release the working tree lock, if held.

This is required if apply has not been invoked, but can be invoked even after apply.

def __get_root(self):
Undocumented
def _assign_id(self):
Produce a new tranform id
def create_path(self, name, parent):
Assign a transaction id to a new path
def adjust_path(self, name, parent, trans_id):
Change the path that is assigned to a transaction id.
def adjust_root_path(self, name, parent):
Emulate moving the root by moving all children, instead.

We do this by undoing the association of root's transaction id with the current tree. This allows us to create a new directory with that transaction id. We unversion the root directory and version the physically new directory, and hope someone versions the tree root later.

def fixup_new_roots(self):
Reinterpret requests to change the root directory

Instead of creating a root directory, or moving an existing directory, all the attributes and children of the new root are applied to the existing root directory.

This means that the old root trans-id becomes obsolete, so it is recommended only to invoke this after the root trans-id has become irrelevant.

def trans_id_tree_file_id(self, inventory_id):
Determine the transaction id of a working tree file.

This reflects only files that already exist, not ones that will be added by transactions.

def trans_id_file_id(self, file_id):
Determine or set the transaction id associated with a file ID. A new id is only created for file_ids that were never present. If a transaction has been unversioned, it is deliberately still returned. (this will likely lead to an unversioned parent conflict.)
def trans_id_tree_path(self, path):
Determine (and maybe set) the transaction ID for a tree path.
def get_tree_parent(self, trans_id):
Determine id of the parent in the tree.
def delete_contents(self, trans_id):
Schedule the contents of a path entry for deletion
def cancel_deletion(self, trans_id):
Cancel a scheduled deletion
def unversion_file(self, trans_id):
Schedule a path entry to become unversioned
def delete_versioned(self, trans_id):
Delete and unversion a versioned file
def set_executability(self, executability, trans_id):
Schedule setting of the 'execute' bit To unschedule, set to None
def set_tree_reference(self, revision_id, trans_id):
Set the reference associated with a directory
def version_file(self, file_id, trans_id):
Schedule a file to become versioned.
def cancel_versioning(self, trans_id):
Undo a previous versioning of a file
def new_paths(self, filesystem_only=False):
Determine the paths of all new and changed files.
Parametersfilesystem_onlyif True, only calculate values for files that require renames or execute bit changes.
def _inventory_altered(self):
Determine which trans_ids need new Inventory entries.

An new entry is needed when anything that would be reflected by an inventory entry changes, including file name, file_id, parent file_id, file kind, and the execute bit.

Some care is taken to return entries with real changes, not cases where the value is deleted and then restored to its original value, but some actually unchanged values may be returned.

ReturnsA list of (path, trans_id) for all items requiring an inventory change. Ordered by path.
def final_kind(self, trans_id):
Determine the final file kind, after any changes applied.
ReturnsNone if the file does not exist/has no contents. (It is conceivable that a path would be created without the corresponding contents insertion command)
def tree_file_id(self, trans_id):
Determine the file id associated with the trans_id in the tree
def final_file_id(self, trans_id):
Determine the file id after any changes are applied, or None.

None indicates that the file will not be versioned after changes are applied.

def inactive_file_id(self, trans_id):
Return the inactive file_id associated with a transaction id. That is, the one in the tree or in non_present_ids. The file_id may actually be active, too.
def final_parent(self, trans_id):
Determine the parent file_id, after any changes are applied.

ROOT_PARENT is returned for the tree root.

def final_name(self, trans_id):
Determine the final filename, after all changes are applied.
def by_parent(self):
Return a map of parent: children for known parents.

Only new paths and parents of tree files with assigned ids are used.

def path_changed(self, trans_id):
Return True if a trans_id's path has changed.
def new_contents(self, trans_id):
Undocumented
def find_conflicts(self):
Find any violations of inventory or filesystem invariants
def _check_malformed(self):
Undocumented
def _add_tree_children(self):
Add all the children of all active parents to the known paths.

Active parents are those which gain children, and those which are removed. This is a necessary first step in detecting conflicts.

@deprecated_method(deprecated_in((2, 3, 0)))
def has_named_child(self, by_parent, parent_id, name):
Undocumented
def _has_named_child(self, name, parent_id, known_children):
Does a parent already have a name child.
ParametersnameThe searched for name.
parent_idThe parent for which the check is made.
known_childrenThe already known children. This should have been recently obtained from self.by_parent.get(parent_id) (or will be if None is passed).
def _available_backup_name(self, name, target_id):
Find an available backup name.
ParametersnameThe basename of the file.
target_idThe directory trans_id where the backup should be placed.
def _parent_loops(self):
No entry should be its own ancestor
def _unversioned_parents(self, by_parent):
If parent directories are versioned, children must be versioned.
def _improper_versioning(self):
Cannot version a file with no contents, or a bad type.

However, existing entries with no contents are okay.

def _executability_conflicts(self):
Check for bad executability changes.

Only versioned files may have their executability set, because
1. only versioned entries can have executability under windows
2. only files can be executable.  (The execute bit on a directory
   does not indicate searchability)
def _overwrite_conflicts(self):
Check for overwrites (not permitted on Win32)
def _duplicate_entries(self, by_parent):
No directory may have two entries with the same name.
def _duplicate_ids(self):
Each inventory id may only be used once
def _parent_type_conflicts(self, by_parent):
Children must have a directory parent
def _set_executability(self, path, trans_id):
Set the executability of versioned files
def _new_entry(self, name, parent_id, file_id):
Helper function to create a new filesystem entry.
def new_file(self, name, parent_id, contents, file_id=None, executable=None, sha1=None):
Convenience method to create files.

name is the name of the file to create. parent_id is the transaction id of the parent directory of the file. contents is an iterator of bytestrings, which will be used to produce the file. :param file_id: The inventory ID of the file, if it is to be versioned. :param executable: Only valid when a file_id has been supplied.

def new_directory(self, name, parent_id, file_id=None):
Convenience method to create directories.

name is the name of the directory to create. parent_id is the transaction id of the parent directory of the directory. file_id is the inventory ID of the directory, if it is to be versioned.

def new_symlink(self, name, parent_id, target, file_id=None):
Convenience method to create symbolic link.

name is the name of the symlink to create. parent_id is the transaction id of the parent directory of the symlink. target is a bytestring of the target of the symlink. file_id is the inventory ID of the file, if it is to be versioned.

def new_orphan(self, trans_id, parent_id):
Schedule an item to be orphaned.

When a directory is about to be removed, its children, if they are not versioned are moved out of the way: they don't have a parent anymore.

Parameterstrans_idThe trans_id of the existing item.
parent_idThe parent trans_id of the item.
def _get_potential_orphans(self, dir_id):
Find the potential orphans in a directory.

A directory can't be safely deleted if there are versioned files in it. If all the contained files are unversioned then they can be orphaned.

The 'None' return value means that the directory contains at least one versioned file and should not be deleted.

Parametersdir_idThe directory trans id.
ReturnsA list of the orphan trans ids or None if at least one versioned file is present.
def _affected_ids(self):
Return the set of transform ids affected by the transform
def _get_file_id_maps(self):
Return mapping of file_ids to trans_ids in the to and from states
def _from_file_data(self, from_trans_id, from_versioned, file_id):
Get data about a file in the from (tree) state

Return a (name, parent, kind, executable) tuple

def _to_file_data(self, to_trans_id, from_trans_id, from_executable):
Get data about a file in the to (target) state

Return a (name, parent, kind, executable) tuple

def iter_changes(self):
Produce output in the same format as Tree.iter_changes.

Will produce nonsensical results if invoked while inventory/filesystem conflicts (as reported by TreeTransform.find_conflicts()) are present.

This reads the Transform, but only reproduces changes involving a file_id. Files that are not versioned in either of the FROM or TO states are not reflected.

def get_preview_tree(self):
Return a tree representing the result of the transform.

The tree is a snapshot, and altering the TreeTransform will invalidate it.

def commit(self, branch, message, merge_parents=None, strict=False, timestamp=None, timezone=None, committer=None, authors=None, revprops=None, revision_id=None):
Commit the result of this TreeTransform to a branch.
ParametersbranchThe branch to commit to.
messageThe message to attach to the commit.
merge_parentsAdditional parent revision-ids specified by pending merges.
strictIf True, abort the commit if there are unversioned files.
timestampif not None, seconds-since-epoch for the time and date. (May be a float.)
timezoneOptional timezone for timestamp, as an offset in seconds.
committerOptional committer in email-id format. (e.g. "J Random Hacker <jrandom@example.com>")
authorsOptional list of authors in email-id format.
revpropsOptional dictionary of revision properties.
revision_idOptional revision id. (Specifying a revision-id may reduce performance for some non-native formats.)
ReturnsThe revision_id of the revision committed.
def _text_parent(self, trans_id):
Undocumented
def _get_parents_texts(self, trans_id):
Get texts for compression parents of this file.
def _get_parents_lines(self, trans_id):
Get lines for compression parents of this file.
def serialize(self, serializer):
Serialize this TreeTransform.
ParametersserializerA Serialiser like pack.ContainerSerializer.
def deserialize(self, records):
Deserialize a stored TreeTransform.
ParametersrecordsAn iterable of (names, content) tuples, as per pack.ContainerPushParser.
API Documentation for Bazaar, generated by pydoctor at 2019-11-20 00:36:28.