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.
SubmodulePorcelainFlags
Submodule dirty bits aligned with Git’s DIRTY_SUBMODULE_* / porcelain v2 S??? token.

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.
count_changes_with_algorithm
Count insertions and deletions using the given line-diff algorithm.
count_git_lines
Line count for diffstat/--numstat, matching Git’s count_lines() in diff.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_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).
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_index in Git’s diff.c).
rewrite_merge_score
Git merge_score from diffcore-break.c when a pair is considered broken: how much of the source blob was removed (0–[DIFF_MAX_SCORE] scale). Used for dissimilarity index metadata.
should_break_rewrite_for_stat
Whether this modified blob pair should use Git’s “complete rewrite” diffstat path when --break-rewrites is in effect (should_break in diffcore-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 to super_worktree) and return flags used for git status --porcelain=v2 submodule tokens.
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.
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.