module documentation

Diff functionality with separate codepaths.

This module provides three main functions for different diff scenarios:

  1. diff_index_to_tree: Shows staged changes (index vs commit) Used by: git diff --staged, git diff --cached
  2. diff_working_tree_to_tree: Shows all changes from a commit to working tree Used by: git diff <commit>
  3. diff_working_tree_to_index: Shows unstaged changes (working tree vs index) Used by: git diff (with no arguments)
Example usage:

from dulwich.repo import Repo from dulwich.diff import diff_index_to_tree import sys

repo = Repo('.') # Show staged changes diff_index_to_tree(repo, sys.stdout.buffer)

# Show changes in specific paths only diff_index_to_tree(repo, sys.stdout.buffer, paths=[b'src/', b'README.md'])

Class ColorizedDiffStream Stream wrapper that colorizes diff output line by line using Rich.
Function diff_index_to_tree Show staged changes (index vs commit).
Function diff_working_tree_to_index Compare working tree to index.
Function diff_working_tree_to_tree Compare working tree to a specific commit.
Function should_include_path Check if a path should be included based on path filters.
Variable logger Undocumented
def diff_index_to_tree(repo: Repo, outstream: BinaryIO, commit_sha: ObjectID | None = None, paths: Sequence[bytes] | None = None, diff_algorithm: str | None = None):

Show staged changes (index vs commit).

Parameters
repo:RepoRepository object
outstream:BinaryIOStream to write diff to
commit_sha:ObjectID | NoneSHA of commit to compare against, or None for HEAD
paths:Sequence[bytes] | NoneOptional list of paths to filter (as bytes)
diff_algorithm:str | NoneAlgorithm to use for diffing ("myers" or "patience"), defaults to DEFAULT_DIFF_ALGORITHM if None
def diff_working_tree_to_index(repo: Repo, outstream: BinaryIO, paths: Sequence[bytes] | None = None, diff_algorithm: str | None = None):

Compare working tree to index.

Parameters
repo:RepoRepository object
outstream:BinaryIOStream to write diff to
paths:Sequence[bytes] | NoneOptional list of paths to filter (as bytes)
diff_algorithm:str | NoneAlgorithm to use for diffing ("myers" or "patience"), defaults to DEFAULT_DIFF_ALGORITHM if None
def diff_working_tree_to_tree(repo: Repo, outstream: BinaryIO, commit_sha: ObjectID, paths: Sequence[bytes] | None = None, diff_algorithm: str | None = None):

Compare working tree to a specific commit.

Parameters
repo:RepoRepository object
outstream:BinaryIOStream to write diff to
commit_sha:ObjectIDSHA of commit to compare against
paths:Sequence[bytes] | NoneOptional list of paths to filter (as bytes)
diff_algorithm:str | NoneAlgorithm to use for diffing ("myers" or "patience"), defaults to DEFAULT_DIFF_ALGORITHM if None
def should_include_path(path: bytes, paths: Sequence[bytes] | None) -> bool:

Check if a path should be included based on path filters.

Parameters
path:bytesThe path to check
paths:Sequence[bytes] | NoneList of path filters, or None for no filtering
Returns
boolTrue if the path should be included
logger =

Undocumented