Skip to main content

Module diff_text

Module diff_text 

Source
Expand description

Unified-diff text to FileDiffs, with no I/O: the one parser behind the system-git backend (git diff output) and the hosting API diffs (a host’s per-file patch, which has hunks but no diff --git header).

Lines are split with str::lines, so a \r\n terminator is dropped like a \n: a CRLF patch parses as the same lines as an LF one. A \ No newline at end of file marker is not a line of the file and is skipped.

Functions§

parse_hunks
Parses the hunks of one file’s patch (what a hosting API returns per file: @@ -a,b +c,d @@ sections, no diff --git / --- / +++ header) into a FileDiff for path with the given status. Anything before the first @@ line is skipped, so a patch that does carry ---/+++ lines parses the same. An empty patch (a binary file, a mode change, a rename without edits) has no hunks.
parse_unified
Parses a whole git diff output: one FileDiff per diff --git header, its status read from the extended header lines (new file mode, deleted file mode, rename from|to).