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

Function trackBulkFileChanges

src/utils/commitAttribution.ts:490–543  ·  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

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

Callers

nothing calls this directly

Calls 6

normalizeFilePathFunction · 0.85
nowMethod · 0.80
setMethod · 0.80
logForDebuggingFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected