MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / computeDiffStatsForFile

Function computeDiffStatsForFile

src/utils/fileHistory.ts:677–723  ·  view source on GitHub ↗

* Computes the number of lines changed in the diff.

(
  originalFile: string,
  backupFileName?: string,
)

Source from the content-addressed store, hash-verified

675 * Computes the number of lines changed in the diff.
676 */
677async function computeDiffStatsForFile(
678 originalFile: string,
679 backupFileName?: string,
680): Promise<DiffStats> {
681 const filesChanged: string[] = []
682 let insertions = 0
683 let deletions = 0
684 try {
685 const backupPath = backupFileName
686 ? resolveBackupPath(backupFileName)
687 : undefined
688
689 const [originalContent, backupContent] = await Promise.all([
690 readFileAsyncOrNull(originalFile),
691 backupPath ? readFileAsyncOrNull(backupPath) : null,
692 ])
693
694 if (originalContent === null && backupContent === null) {
695 return {
696 filesChanged,
697 insertions,
698 deletions,
699 }
700 }
701
702 filesChanged.push(originalFile)
703
704 // Compute the diff
705 const changes = diffLines(originalContent ?? '', backupContent ?? '')
706 changes.forEach(c => {
707 if (c.added) {
708 insertions += c.count || 0
709 }
710 if (c.removed) {
711 deletions += c.count || 0
712 }
713 })
714 } catch (error) {
715 logError(new Error(`FileHistory: Error generating diffStats: ${error}`))
716 }
717
718 return {
719 filesChanged,
720 insertions,
721 deletions,
722 }
723}
724
725function getBackupFileName(filePath: string, version: number): string {
726 const fileNameHash = createHash('sha256')

Callers 1

fileHistoryGetDiffStatsFunction · 0.85

Calls 3

resolveBackupPathFunction · 0.85
readFileAsyncOrNullFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected