Skip to main content

parse_unified_diff

Function parse_unified_diff 

Source
pub fn parse_unified_diff(input: &str) -> DiffDocument
Expand description

Parse a git diff output into a DiffDocument.

Handles:

  • diff --git a/X b/Y file headers
  • rename from X / rename to Y — populates DiffFile::old_path
  • similarity index N% — currently skipped (recorded but not exposed)
  • new file mode ... / deleted file mode ... — skipped
  • Binary files X and Y differ — sets DiffFile::binary and emits no hunks
  • index abc..def 100644 — skipped
  • --- a/X / +++ b/Y — consumed as part of the file header
  • @@ -old,count +new,count @@ — hunk headers
  • context / + / - lines

Multiple files are supported and emitted in source order.