Skip to main content

unified_hunks

Function unified_hunks 

Source
pub fn unified_hunks(old_bytes: &[u8], new_bytes: &[u8]) -> Option<Vec<u8>>
Expand description

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.

Splitting the hunk body out lets callers wrap it in a git-shaped diff --git header (with /dev/null for adds/deletes) while keeping the algorithm — Myers diff with git-style hunk compaction — in one place.