MCPcopy
hub / github.com/claude-code-best/claude-code / computeDiffStatsForFile

Function computeDiffStatsForFile

src/utils/fileHistory.ts:679–725  ·  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

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

Callers 1

fileHistoryGetDiffStatsFunction · 0.85

Calls 4

resolveBackupPathFunction · 0.85
readFileAsyncOrNullFunction · 0.85
logErrorFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected