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.
- Submodule
Porcelain Flags - Submodule dirty bits aligned with Git’s
DIRTY_SUBMODULE_*/ porcelain v2S???token.
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.
- count_
changes_ with_ algorithm - Count insertions and deletions using the given line-diff algorithm.
- count_
git_ lines - Line count for diffstat/
--numstat, matching Git’scount_lines()indiff.c. - 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). - diffcore_
count_ changes - Approximate copied vs added material between two blobs (Git
diffcore_count_changes). - empty_
blob_ oid - Return the ObjectId for the empty blob object.
- format_
mode - Format a numeric mode as a zero-padded octal string.
- 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 - hash_
worktree_ file - head_
path_ states - Paths present in
HEAD’s tree with mode and blob/commit OID (for status porcelain v2). - mode_
from_ metadata - Derive a Git file mode from filesystem metadata.
- read_
submodule_ head_ for_ checkout - Read the HEAD commit OID from a submodule checkout directory.
- read_
submodule_ head_ oid - Read the HEAD commit OID from a submodule working tree directory.
- rename_
similarity_ score - Compute rename/copy similarity percentage (0–100) between two byte slices.
- rewrite_
dissimilarity_ index_ percent - Percentage shown in
dissimilarity index N%for a rewrite (similarity_indexin Git’s diff.c). - rewrite_
merge_ score - Git
merge_scorefromdiffcore-break.cwhen a pair is considered broken: how much of the source blob was removed (0–[DIFF_MAX_SCORE] scale). Used fordissimilarity indexmetadata. - should_
break_ rewrite_ for_ stat - Whether this modified blob pair should use Git’s “complete rewrite” diffstat path when
--break-rewritesis in effect (should_breakindiffcore-break.c). - stat_
matches - status_
apply_ rename_ copy_ detection - Apply Git-style rename and optional copy detection for index↔worktree diffs.
- submodule_
embedded_ git_ dir - Resolve the embedded git directory for a submodule work tree (
sub_dir/.git). - submodule_
porcelain_ flags - Inspect a checked-out submodule at
rel_path(relative tosuper_worktree) and return flags used forgit status --porcelain=v2submodule tokens. - 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. - worktree_
differs_ from_ index_ entry - Quick stat check: does the index entry’s cached stat data match the file?
Returns true when the file at
ie’s path differs from the index entry (mode or blob). - zero_
oid - Return the zero ObjectId.