Skip to main content

reverse_apply_hunks

Function reverse_apply_hunks 

Source
pub fn reverse_apply_hunks(
    current: &str,
    hunks: &[DiffHunk],
) -> Result<String, ReverseApplyError>
Expand description

Reverses structured hunks against current content, returning the pre-image.

Each hunk’s new-side block must occur exactly once in current, and the matches must run in hunk order without overlap. Edits outside the matched spans are preserved; edits inside them refuse the whole file.

§Requires

§Ensures

  • Ok(pre) replaces exactly the recorded new-side blocks with their old-side counterparts; Err computes nothing partial (pure).
  • Total (terminating): bounded scans over current and hunks.