Skip to main content

Module diff

Module diff 

Source
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

  1. Tree-to-tree — compare two tree objects (e.g. for log/show).
  2. Tree-to-index — compare a tree (usually HEAD) against the index (staged changes, used by diff --cached and status).
  3. Index-to-worktree — compare index against the working directory (unstaged changes, used by diff and status).

§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§

DiffEntry
A single diff entry representing one changed path.

Enums§

DiffStatus
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_trees but with show_trees flag: when true, emit entries for tree objects themselves in addition to their recursive contents (the -t flag of diff-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_diff but with configurable source/destination prefixes.
unified_diff_with_prefix_and_funcname
Same as unified_diff_with_prefix with optional custom hunk-header function-name matching.
unified_diff_with_prefix_and_funcname_and_algorithm
Same as unified_diff_with_prefix_and_funcname but allows callers to choose the line diff algorithm used for hunk generation.
zero_oid
Return the zero ObjectId.