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

Function trackBulkFileChanges

source code/utils/commitAttribution.ts:491–544  ·  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

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

Callers

nothing calls this directly

Calls 5

normalizeFilePathFunction · 0.85
logForDebuggingFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected