MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / computeUnifiedDiffStats

Function computeUnifiedDiffStats

src/core/diff/stats.ts:24–50  ·  view source on GitHub ↗
(diff?: string)

Source from the content-addressed store, hash-verified

22 * Compute +/− counts from a unified diff (ignores headers/hunk lines)
23 */
24export 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)

Callers 1

computeDiffStatsFunction · 0.85

Calls 1

parsePatchFunction · 0.85

Tested by

no test coverage detected