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

Function getGitDiffSize

source code/utils/commitAttribution.ts:753–790  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

751 * For deleted files, returns the size of the deleted content.
752 */
753export async function getGitDiffSize(filePath: string): Promise<number> {
754 const cwd = getAttributionRepoRoot()
755
756 try {
757 // Use git diff --stat to get a summary of changes
758 const result = await execFileNoThrowWithCwd(
759 gitExe(),
760 ['diff', '--cached', '--stat', '--', filePath],
761 { cwd, timeout: 5000 },
762 )
763
764 if (result.code !== 0 || !result.stdout) {
765 return 0
766 }
767
768 // Parse the stat output to extract additions and deletions
769 // Format: " file | 5 ++---" or " file | 10 +"
770 const lines = result.stdout.split('\n').filter(Boolean)
771 let totalChanges = 0
772
773 for (const line of lines) {
774 // Skip the summary line (e.g., "1 file changed, 3 insertions(+), 2 deletions(-)")
775 if (line.includes('file changed') || line.includes('files changed')) {
776 const insertMatch = line.match(/(\d+) insertions?/)
777 const deleteMatch = line.match(/(\d+) deletions?/)
778
779 // Use line-based changes and approximate chars per line (~40 chars average)
780 const insertions = insertMatch ? parseInt(insertMatch[1]!, 10) : 0
781 const deletions = deleteMatch ? parseInt(deleteMatch[1]!, 10) : 0
782 totalChanges += (insertions + deletions) * 40
783 }
784 }
785
786 return totalChanges
787 } catch {
788 return 0
789 }
790}
791
792/**
793 * Check if a file was deleted in the staged changes.

Callers 1

Calls 2

getAttributionRepoRootFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85

Tested by

no test coverage detected