(diff?: string)
| 22 | * Compute +/− counts from a unified diff (ignores headers/hunk lines) |
| 23 | */ |
| 24 | export function computeUnifiedDiffStats(diff?: string): DiffStats | null { |
| 25 | if (!diff) return null |
| 26 | |
| 27 | try { |
| 28 | const patches = parsePatch(diff) |
| 29 | if (!patches || patches.length === 0) return null |
| 30 | |
| 31 | let added = 0 |
| 32 | let removed = 0 |
| 33 | |
| 34 | for (const p of patches) { |
| 35 | for (const h of (p as any).hunks ?? []) { |
| 36 | for (const l of h.lines ?? []) { |
| 37 | const ch = (l as string)[0] |
| 38 | if (ch === "+") added++ |
| 39 | else if (ch === "-") removed++ |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if (added > 0 || removed > 0) return { added, removed } |
| 45 | return { added: 0, removed: 0 } |
| 46 | } catch { |
| 47 | // If parsing fails for any reason, signal no stats |
| 48 | return null |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Compute diff stats from any supported diff format (unified or search-replace) |
no test coverage detected