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

Function calculateCommitAttribution

src/utils/commitAttribution.ts:548–743  ·  view source on GitHub ↗
(
  states: AttributionState[],
  stagedFiles: string[],
)

Source from the content-addressed store, hash-verified

546 * Compares session baseline to committed state.
547 */
548export async function calculateCommitAttribution(
549 states: AttributionState[],
550 stagedFiles: string[],
551): Promise<AttributionData> {
552 const cwd = getAttributionRepoRoot()
553 const sessionId = getSessionId()
554
555 const files: Record<string, FileAttribution> = {}
556 const excludedGenerated: string[] = []
557 const surfaces = new Set<string>()
558 const surfaceCounts: Record<string, number> = {}
559
560 let totalClaudeChars = 0
561 let totalHumanChars = 0
562
563 // Merge file states from all sessions
564 const mergedFileStates = new Map<string, FileAttributionState>()
565 const mergedBaselines = new Map<
566 string,
567 { contentHash: string; mtime: number }
568 >()
569
570 for (const state of states) {
571 surfaces.add(state.surface)
572
573 // Merge baselines (earliest baseline wins)
574 // Handle both Map and plain object (in case of serialization)
575 const baselines =
576 state.sessionBaselines instanceof Map
577 ? state.sessionBaselines
578 : new Map(
579 Object.entries(
580 (state.sessionBaselines ?? {}) as Record<
581 string,
582 { contentHash: string; mtime: number }
583 >,
584 ),
585 )
586 for (const [path, baseline] of baselines) {
587 if (!mergedBaselines.has(path)) {
588 mergedBaselines.set(path, baseline)
589 }
590 }
591
592 // Merge file states (accumulate contributions)
593 // Handle both Map and plain object (in case of serialization)
594 const fileStates =
595 state.fileStates instanceof Map
596 ? state.fileStates
597 : new Map(
598 Object.entries(
599 (state.fileStates ?? {}) as Record<string, FileAttributionState>,
600 ),
601 )
602 for (const [path, fileState] of fileStates) {
603 const existing = mergedFileStates.get(path)
604 if (existing) {
605 mergedFileStates.set(path, {

Callers 1

getPRAttributionDataFunction · 0.85

Calls 13

getAttributionRepoRootFunction · 0.85
getSessionIdFunction · 0.85
isGeneratedFileFunction · 0.85
isFileDeletedFunction · 0.85
getGitDiffSizeFunction · 0.85
statFunction · 0.85
entriesMethod · 0.80
maxMethod · 0.80
getMethod · 0.65
addMethod · 0.45
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected