module documentation

Utilities for diffing files and trees.

Class RenameDetector Object for handling rename detection between two trees.
Class TreeChange Named tuple a single change between two trees.
Function tree_changes Find the differences between the contents of two trees.
Function tree_changes_for_merge Get the tree changes for a merge tree relative to all its parents.
Function walk_trees Recursively walk all the entries of two trees.
Constant CHANGE_ADD Undocumented
Constant CHANGE_COPY Undocumented
Constant CHANGE_DELETE Undocumented
Constant CHANGE_MODIFY Undocumented
Constant CHANGE_RENAME Undocumented
Constant CHANGE_UNCHANGED Undocumented
Constant MAX_FILES Undocumented
Constant RENAME_CHANGE_TYPES Undocumented
Constant RENAME_THRESHOLD Undocumented
Constant REWRITE_THRESHOLD Undocumented
Function _all_eq Undocumented
Function _all_same Undocumented
Function _common_bytes Count the number of common bytes in two block count dicts.
Function _count_blocks Count the blocks in an object.
Function _is_tree Undocumented
Function _merge_entries Merge the entries of two trees.
Function _similarity_score Compute a similarity score for two objects.
Function _skip_tree Undocumented
Function _tree_change_key Undocumented
Function _tree_entries Undocumented
Constant _BLOCK_SIZE Undocumented
Constant _MAX_SCORE Undocumented
Constant _NULL_ENTRY Undocumented
def tree_changes(store, tree1_id, tree2_id, want_unchanged=False, rename_detector=None, include_trees=False, change_type_same=False):

Find the differences between the contents of two trees.

Parameters
storeAn ObjectStore for looking up objects.
tree1_idThe SHA of the source tree.
tree2_idThe SHA of the target tree.
want_unchangedIf True, include TreeChanges for unmodified entries as well.
rename_detectorRenameDetector object for detecting renames.
include_treesWhether to include trees
change_type_sameWhether to report change types in the same entry or as delete+add.
Returns
Iterator over TreeChange instances for each change between the
source and target tree.
def tree_changes_for_merge(store, parent_tree_ids, tree_id, rename_detector=None):

Get the tree changes for a merge tree relative to all its parents.

Parameters
storeAn ObjectStore for looking up objects.
parent_tree_idsAn iterable of the SHAs of the parent trees.
tree_idThe SHA of the merge tree.
rename_detectorRenameDetector object for detecting renames.
Returns

Iterator over lists of TreeChange objects, one per conflicted path in the merge.

Each list contains one element per parent, with the TreeChange for that path relative to that parent. An element may be None if it never existed in one parent and was deleted in two others.

A path is only included in the output if it is a conflict, i.e. its SHA in the merge tree is not found in any of the parents, or in the case of deletes, if not all of the old SHAs match.

def walk_trees(store, tree1_id, tree2_id, prune_identical=False):

Recursively walk all the entries of two trees.

Iteration is depth-first pre-order, as in e.g. os.walk.

Parameters
storeAn ObjectStore for looking up objects.
tree1_idThe SHA of the first Tree object to iterate, or None.
tree2_idThe SHA of the second Tree object to iterate, or None.
prune_identicalIf True, identical subtrees will not be walked.
Returns
Iterator over Pairs of TreeEntry objects for each pair of entries
in the trees and their subtrees recursively. If an entry exists in one tree but not the other, the other entry will have all attributes set to None. If neither entry's path is None, they are guaranteed to match.
CHANGE_ADD: str =

Undocumented

Value
'add'
CHANGE_COPY: str =

Undocumented

Value
'copy'
CHANGE_DELETE: str =

Undocumented

Value
'delete'
CHANGE_MODIFY: str =

Undocumented

Value
'modify'
CHANGE_RENAME: str =

Undocumented

Value
'rename'
CHANGE_UNCHANGED: str =

Undocumented

Value
'unchanged'
MAX_FILES: int =

Undocumented

Value
200
RENAME_CHANGE_TYPES =

Undocumented

Value
(CHANGE_RENAME, CHANGE_COPY)
RENAME_THRESHOLD: int =

Undocumented

Value
60
REWRITE_THRESHOLD =

Undocumented

Value
None
def _all_eq(seq, key, value):

Undocumented

def _all_same(seq, key):

Undocumented

def _common_bytes(blocks1, blocks2):

Count the number of common bytes in two block count dicts.

Parameters
blocks1The first dict of block hashcode -> total bytes.
blocks2The second dict of block hashcode -> total bytes.
Returns
The number of bytes in common between blocks1 and blocks2. This is only approximate due to possible hash collisions.
def _count_blocks(obj):

Count the blocks in an object.

Splits the data into blocks either on lines or <=64-byte chunks of lines.

Parameters
objThe object to count blocks for.
Returns
A dict of block hashcode -> total bytes occurring.
def _is_tree(entry):

Undocumented

def _merge_entries(path, tree1, tree2):

Merge the entries of two trees.

Parameters
pathA path to prepend to all tree entry names.
tree1The first Tree object to iterate, or None.
tree2The second Tree object to iterate, or None.
Returns
A list of pairs of TreeEntry objects for each pair of entries in
the trees. If an entry exists in one tree but not the other, the other entry will have all attributes set to None. If neither entry's path is None, they are guaranteed to match.
def _similarity_score(obj1, obj2, block_cache=None):

Compute a similarity score for two objects.

Parameters
obj1The first object to score.
obj2The second object to score.
block_cacheAn optional dict of SHA to block counts to cache results between calls.
Returns
The similarity score between the two objects, defined as the
number of bytes in common between the two objects divided by the maximum size, scaled to the range 0-100.
def _skip_tree(entry, include_trees):

Undocumented

def _tree_change_key(entry):

Undocumented

def _tree_entries(path, tree):

Undocumented

_BLOCK_SIZE: int =

Undocumented

Value
64
_MAX_SCORE: int =

Undocumented

Value
100
_NULL_ENTRY =

Undocumented

Value
TreeEntry(None, None, None)