pub fn parse_unified_diff(diff_text: &str) -> Vec<Hunk>Expand description
Parse the output of git diff --unified=N into hunks.
Tolerant by design: anything it does not recognise is skipped rather than erroring, because a diff that cannot be parsed must not take the gate down. The intentional quirks:
- The file path comes from
+++ b/…, never fromdiff --git a/… b/…. The git header carries two paths on one line with no unambiguous separator, so any “findb/” rule captures the wrong span for a repository path that itself containsb/(src/b/mod.rs). The Pythondiff_parser.pythis replaces had exactly that bug. +++ /dev/nullmarks a deletion; there is nothing to analyze, so the file’s hunks are dropped.- Inside a hunk body the first byte alone decides the line kind. Lines
starting
---or+++are not additionally skipped: those headers appear only before the first@@of a file, and a removed source line whose own text begins with--arrives as---…. Skipping it silently drops real removed code — the second bug in the Python. \ No newline at end of filerefers to the preceding line and never becomes aHunkLine.- A malformed
@@terminates the current hunk without its body being attributed to the previous one.