Expand description
Diff machinery — compare trees, index entries, and working tree files.
§Overview
This module provides the core diffing infrastructure shared by diff,
diff-index, status, log, show, commit, and merge.
§Levels of comparison
- Tree-to-tree — compare two tree objects (e.g. for
log/show). - Tree-to-index — compare a tree (usually HEAD) against the index
(staged changes, used by
diff --cachedandstatus). - Index-to-worktree — compare index against the working directory
(unstaged changes, used by
diffandstatus).
§Content diff
Line-level diffing uses the Myers algorithm via the similar crate.
Output formats: unified patch, raw (:old-mode new-mode ...), stat,
numstat.
Structs§
- Diff
Entry - A single diff entry representing one changed path.
Enums§
- Diff
Status - The kind of change between two sides of a diff.
Constants§
- ZERO_
OID - The zero (null) object ID used for “no object” in diff output.
Functions§
- anchored_
unified_ diff - Compute a unified diff with anchored lines.
- count_
changes - Count insertions and deletions between two strings.
- detect_
copies - Detect copies among diff entries.
- detect_
renames - Detect renames by pairing Deleted and Added entries with similar content.
- diff_
index_ to_ tree - Compare the index against a tree (usually HEAD’s tree).
- diff_
index_ to_ worktree - Compare the index against the working tree.
- diff_
tree_ to_ worktree - Compare a tree against the working tree.
- diff_
trees - Compare two trees and return the list of changed entries.
- diff_
trees_ show_ tree_ entries - Like
diff_treesbut withshow_treesflag: when true, emit entries for tree objects themselves in addition to their recursive contents (the-tflag ofdiff-tree). - empty_
blob_ oid - Return the ObjectId for the empty blob object.
- format_
raw - Format a diff entry in Git’s raw diff format.
- format_
raw_ abbrev - Format a diff entry with abbreviated OIDs.
- format_
rename_ path - Format a rename pair using Git’s compact path format.
- format_
stat_ line - Generate diff stat output (file name + insertions/deletions).
- format_
stat_ line_ width - rename_
similarity_ score - Compute rename/copy similarity percentage (0–100) between two byte slices.
- stat_
matches - Quick stat check: does the index entry’s cached stat data match the file?
- unified_
diff - Generate a unified diff patch for two blobs.
- unified_
diff_ with_ prefix - Same as
unified_diffbut with configurable source/destination prefixes. - unified_
diff_ with_ prefix_ and_ funcname - Same as
unified_diff_with_prefixwith optional custom hunk-header function-name matching. - unified_
diff_ with_ prefix_ and_ funcname_ and_ algorithm - Same as
unified_diff_with_prefix_and_funcnamebut allows callers to choose the line diff algorithm used for hunk generation. - zero_
oid - Return the zero ObjectId.