Skip to main content

apply_hunks_subset

Function apply_hunks_subset 

Source
pub fn apply_hunks_subset(
    base_bytes: &[u8],
    hunks: &[PatchHunk],
    selected: &[usize],
) -> Vec<u8> 
Expand description

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.

This is the staging primitive for add -p: pass the index/HEAD blob as the base and the accepted hunk indices to produce the partially-staged blob. Applying all hunks reproduces the new blob exactly; applying none reproduces the base.