| 363 | } |
| 364 | |
| 365 | export function countDiffStats(hunks: (DiffHunk | DiffSkipBlock)[]): { |
| 366 | additions: number |
| 367 | deletions: number |
| 368 | } { |
| 369 | let additions = 0 |
| 370 | let deletions = 0 |
| 371 | |
| 372 | for (const hunk of hunks) { |
| 373 | if (hunk.type === 'hunk') { |
| 374 | for (const line of hunk.lines) { |
| 375 | if (line.type === 'insert') additions++ |
| 376 | else if (line.type === 'delete') deletions++ |
| 377 | else if (line.type === 'normal') { |
| 378 | // Merged modified lines have type 'normal' but contain inline |
| 379 | // insert/delete segments. Count them as both an addition and deletion. |
| 380 | const hasInlineChanges = line.content.some( |
| 381 | seg => seg.type === 'insert' || seg.type === 'delete', |
| 382 | ) |
| 383 | if (hasInlineChanges) { |
| 384 | additions++ |
| 385 | deletions++ |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | return { additions, deletions } |
| 393 | } |