Skip to main content

Module diff

Module diff 

Source
Expand description

Tree-level structural diff.

Compares two trees identified by their object hash and returns the minimal list of leaf-level changes (added / removed / modified / mode_changed). The walk is lockstep over the two sorted entry arrays, recurses into matching subtrees only when their hashes differ, and treats added/removed subtrees as bulk operations on every contained leaf.

Also contains status_diff — the working-tree vs HEAD diff that powers mkit status.

Structs§

DiffEntry
One leaf-level change. path is /-joined relative to the root of the compared trees; subtree directories are NOT emitted as their own entries — only the leaves they contain.
DiffResult
Sorted (by path) sequence of DiffEntry.
HunkLine
One line of a hunk: its origin plus the raw bytes (no +/-/space prefix) and whether the source line had a trailing newline.
PatchHunk
A single hunk for interactive staging (add -p): the 1-based old/new line ranges (as in the @@ header) plus the ordered context/added/ removed lines. Use apply_hunks_subset to materialize a chosen subset.
StatusEntry
One entry in the mkit status output. Combines a DiffEntry with index-awareness so the caller can render three-way status output.

Enums§

DiffError
Error type for status_diff.
DiffKind
What kind of change a DiffEntry represents.
HunkLineKind
Origin of a line within a PatchHunk — context (unchanged), added on the new side, or removed from the old side.
StatusStaging
Staging state of a StatusEntry relative to the index.

Functions§

apply_hunks_subset
Rebuild a blob from base_bytes applying only the hunks whose index (into the slice returned by enumerate_hunks) is in selected. Selected hunks have their additions applied and removals dropped; unselected hunks keep the base content unchanged. selected order does not matter — hunks are always applied in file order — and out-of-range indices are ignored.
diff_line_counts
Added / deleted line counts between two blobs, from the same Myers edit script the unified patch uses. None when either side is binary — matching Git’s heuristic of a NUL byte within the first 8000 bytes (independent of UTF-8 validity), so diff --stat renders Bin … for exactly the blobs Git would.
diff_trees
Compare two trees and return their DiffResult. None for either hash represents the empty tree (use cases: comparing against the initial commit, against a rolled-back state).
enumerate_hunks
Enumerate the hunks between two blobs as structured PatchHunks, using the same Myers diff + git-style compaction as unified_hunks. Returns None when either side is binary (git’s NUL heuristic); an empty vector means the blobs are textually identical. Unlike unified_hunks, which renders bytes, this exposes each hunk’s lines so a caller can let the user pick a subset to stage and rebuild the partial blob with apply_hunks_subset.
merge_blob_3way
Line-level 3-way merge of three blobs (diff3-style, conservative).
status_diff
Compare HEAD ↔ index and index ↔ worktree, returning a list of StatusEntry grouped by staging state.
status_diff_observed
status_diff that additionally returns the worktree walk’s worktree::StatObservations — entries whose cache was absent or racy-smudged but whose re-hash matched the staged hash. Callers (the status CLI) use them to heal the stat cache from hash-time stats; pairing a later stat with the earlier hash is unsound.
text_patch
Render a unified-diff patch between two byte blobs.
unified_hunks
The hunk body of a unified diff between two blobs: the @@ … @@ headers and their +/-/context lines, with no ---/+++ file headers, as raw bytes (git diffs are byte-oriented and do not require UTF-8). Returns None when either side is binary by git’s heuristic — a NUL byte in the first 8000 bytes — so a caller emits a Binary files … line instead. An empty result means the blobs are textually identical.