MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseDiffStats

Function parseDiffStats

cli/src/utils/implementor-helpers.ts:485–514  ·  view source on GitHub ↗
(diff: string | undefined)

Source from the content-addressed store, hash-verified

483 * Parse diff text and extract statistics.
484 */
485export function parseDiffStats(diff: string | undefined): DiffStats {
486 if (!diff) return { linesAdded: 0, linesRemoved: 0, hunks: 0 }
487
488 const lines = diff.split('\n')
489 let linesAdded = 0
490 let linesRemoved = 0
491 let hunks = 0
492
493 for (const line of lines) {
494 // Count hunk headers (lines starting with @@)
495 if (line.startsWith('@@')) {
496 hunks++
497 }
498 // Count additions (lines starting with + but not +++ header)
499 else if (line.startsWith('+') && !line.startsWith('+++')) {
500 linesAdded++
501 }
502 // Count deletions (lines starting with - but not --- header)
503 else if (line.startsWith('-') && !line.startsWith('---')) {
504 linesRemoved++
505 }
506 }
507
508 // If no @@ markers found but we have +/- lines, count as 1 hunk
509 if (hunks === 0 && (linesAdded > 0 || linesRemoved > 0)) {
510 hunks = 1
511 }
512
513 return { linesAdded, linesRemoved, hunks }
514}
515
516/**
517 * Determine file change type based on tool and context.

Callers 2

getFileStatsFromBlocksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected