MCPcopy Index your code
hub / github.com/codeaashu/claude-code / trackBulkFileChanges

Function trackBulkFileChanges

src/utils/commitAttribution.ts:489–542  ·  view source on GitHub ↗
(
  state: AttributionState,
  changes: ReadonlyArray<{
    path: string
    type: 'modified' | 'created' | 'deleted'
    oldContent: string
    newContent: string
    mtime?: number
  }>,
)

Source from the content-addressed store, hash-verified

487 * large git diffs (e.g., jj operations that touch hundreds of thousands of files).
488 */
489export function trackBulkFileChanges(
490 state: AttributionState,
491 changes: ReadonlyArray<{
492 path: string
493 type: 'modified' | 'created' | 'deleted'
494 oldContent: string
495 newContent: string
496 mtime?: number
497 }>,
498): AttributionState {
499 // Create ONE copy of the Map, then mutate it for each file
500 const newFileStates = new Map(state.fileStates)
501
502 for (const change of changes) {
503 const mtime = change.mtime ?? Date.now()
504 if (change.type === 'deleted') {
505 const normalizedPath = normalizeFilePath(change.path)
506 const existingState = newFileStates.get(normalizedPath)
507 const existingContribution = existingState?.claudeContribution ?? 0
508 const deletedChars = change.oldContent.length
509
510 newFileStates.set(normalizedPath, {
511 contentHash: '',
512 claudeContribution: existingContribution + deletedChars,
513 mtime,
514 })
515
516 logForDebugging(
517 `Attribution: Tracked deletion of ${normalizedPath} (${deletedChars} chars removed, total contribution: ${existingContribution + deletedChars})`,
518 )
519 } else {
520 const newFileState = computeFileModificationState(
521 newFileStates,
522 change.path,
523 change.oldContent,
524 change.newContent,
525 mtime,
526 )
527 if (newFileState) {
528 const normalizedPath = normalizeFilePath(change.path)
529 newFileStates.set(normalizedPath, newFileState)
530
531 logForDebugging(
532 `Attribution: Tracked ${newFileState.claudeContribution} chars for ${normalizedPath}`,
533 )
534 }
535 }
536 }
537
538 return {
539 ...state,
540 fileStates: newFileStates,
541 }
542}
543
544/**
545 * Calculate final attribution for staged files.

Callers

nothing calls this directly

Calls 5

normalizeFilePathFunction · 0.85
logForDebuggingFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected