MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseRawDiffToToolUseDiff

Function parseRawDiffToToolUseDiff

source code/utils/gitDiff.ts:450–483  ·  view source on GitHub ↗

* Parse raw unified diff output into the structured ToolUseDiff format. * Extracts only the hunk content (starting from @@) as the patch, * and counts additions/deletions.

(
  filename: string,
  rawDiff: string,
  status: 'modified' | 'added',
)

Source from the content-addressed store, hash-verified

448 * and counts additions/deletions.
449 */
450function parseRawDiffToToolUseDiff(
451 filename: string,
452 rawDiff: string,
453 status: 'modified' | 'added',
454): Omit<ToolUseDiff, 'repository'> {
455 const lines = rawDiff.split('\n')
456 const patchLines: string[] = []
457 let inHunks = false
458 let additions = 0
459 let deletions = 0
460
461 for (const line of lines) {
462 if (line.startsWith('@@')) {
463 inHunks = true
464 }
465 if (inHunks) {
466 patchLines.push(line)
467 if (line.startsWith('+') && !line.startsWith('+++')) {
468 additions++
469 } else if (line.startsWith('-') && !line.startsWith('---')) {
470 deletions++
471 }
472 }
473 }
474
475 return {
476 filename,
477 status,
478 additions,
479 deletions,
480 changes: additions + deletions,
481 patch: patchLines.join('\n'),
482 }
483}
484
485/**
486 * Determine the best ref to diff against for a PR-like diff.

Callers 1

fetchSingleFileGitDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected