dulwich.diff_tree module

Utilities for diffing files and trees.

class dulwich.diff_tree.RenameDetector(store, rename_threshold=60, max_files=200, rewrite_threshold=None, find_copies_harder=False)

Bases: object

Object for handling rename detection between two trees.

Initialize the rename detector.

  • store – An ObjectStore for looking up objects.

  • rename_threshold – The threshold similarity score for considering an add/delete pair to be a rename/copy; see _similarity_score.

  • max_files – The maximum number of adds and deletes to consider, or None for no limit. The detector is guaranteed to compare no more than max_files ** 2 add/delete pairs. This limit is provided because rename detection can be quadratic in the project size. If the limit is exceeded, no content rename detection is attempted.

  • rewrite_threshold – The threshold similarity score below which a modify should be considered a delete/add, or None to not break modifies; see _similarity_score.

  • find_copies_harder – If True, consider unmodified files when detecting copies.

changes_with_renames(tree1_id, tree2_id, want_unchanged=False, include_trees=False)

Iterate TreeChanges between two tree SHAs, with rename detection.

class dulwich.diff_tree.TreeChange(type, old, new)

Bases: TreeChange

Named tuple a single change between two trees.

Create new instance of TreeChange(type, old, new)

classmethod add(new)
classmethod delete(old)
dulwich.diff_tree.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.

  • store – An ObjectStore for looking up objects.

  • tree1_id – The SHA of the source tree.

  • tree2_id – The SHA of the target tree.

  • want_unchanged – If True, include TreeChanges for unmodified entries as well.

  • include_trees – Whether to include trees

  • rename_detector – RenameDetector object for detecting renames.

  • change_type_same – Whether to report change types in the same entry or as delete+add.


Iterator over TreeChange instances for each change between the

source and target tree.

dulwich.diff_tree.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.

  • store – An ObjectStore for looking up objects.

  • parent_tree_ids – An iterable of the SHAs of the parent trees.

  • tree_id – The SHA of the merge tree.

  • rename_detector – RenameDetector object for detecting renames.


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.

dulwich.diff_tree.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.

  • store – An ObjectStore for looking up objects.

  • tree1_id – The SHA of the first Tree object to iterate, or None.

  • tree2_id – The SHA of the second Tree object to iterate, or None.

  • prune_identical – If True, identical subtrees will not be walked.


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.