Skip to main content

render_hunks

Function render_hunks 

Source
pub fn render_hunks(
    out: &mut Vec<u8>,
    old_content: Option<&[u8]>,
    new_content: Option<&[u8]>,
    options: &mut HunkRenderOptions<'_, '_>,
)
Expand description

Render the unified-diff hunk body for a single file change into out.

old_content / new_content are the full blob contents (None for an absent side — a created or deleted file). The function computes the line-level Myers diff, groups changes into hunks with options.context lines of surrounding context (merging nearby groups per options.interhunk), and emits each hunk: the @@ header (with git’s section heading), then the context / - / + lines including \ No newline at end of file markers.

Nothing is written when the contents are identical (no changed lines). This is the body after the per-file metainfo header the caller emits.