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§
- Diff
Entry - One leaf-level change.
pathis/-joined relative to the root of the compared trees; subtree directories are NOT emitted as their own entries — only the leaves they contain. - Diff
Result - Sorted (by path) sequence of
DiffEntry. - Hunk
Line - One line of a hunk: its origin plus the raw bytes (no
+/-/space prefix) and whether the source line had a trailing newline. - Patch
Hunk - 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. Useapply_hunks_subsetto materialize a chosen subset. - Status
Entry - One entry in the
mkit statusoutput. Combines aDiffEntrywith index-awareness so the caller can render three-way status output.
Enums§
- Diff
Error - Error type for
status_diff. - Diff
Kind - What kind of change a
DiffEntryrepresents. - Hunk
Line Kind - Origin of a line within a
PatchHunk— context (unchanged), added on the new side, or removed from the old side. - Status
Staging - Staging state of a
StatusEntryrelative to the index.
Functions§
- apply_
hunks_ subset - Rebuild a blob from
base_bytesapplying only the hunks whose index (into the slice returned byenumerate_hunks) is inselected. Selected hunks have their additions applied and removals dropped; unselected hunks keep the base content unchanged.selectedorder 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.
Nonewhen either side is binary — matching Git’s heuristic of a NUL byte within the first 8000 bytes (independent of UTF-8 validity), sodiff --statrendersBin …for exactly the blobs Git would. - diff_
trees - Compare two trees and return their
DiffResult.Nonefor 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 asunified_hunks. ReturnsNonewhen either side is binary (git’s NUL heuristic); an empty vector means the blobs are textually identical. Unlikeunified_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 withapply_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
StatusEntrygrouped by staging state. - status_
diff_ observed status_diffthat additionally returns the worktree walk’sworktree::StatObservations — entries whose cache was absent or racy-smudged but whose re-hash matched the staged hash. Callers (thestatusCLI) 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). ReturnsNonewhen either side is binary by git’s heuristic — a NUL byte in the first 8000 bytes — so a caller emits aBinary files …line instead. An empty result means the blobs are textually identical.