MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / extractFileDiffsFromCommit

Function extractFileDiffsFromCommit

evals/buffbench/gen-evals.ts:33–88  ·  view source on GitHub ↗
(
  repoPath: string,
  commitSha: string,
  parentSha: string,
)

Source from the content-addressed store, hash-verified

31}
32
33async function extractFileDiffsFromCommit(
34 repoPath: string,
35 commitSha: string,
36 parentSha: string,
37): Promise<FileDiff[]> {
38 const fileDiffs: FileDiff[] = []
39
40 const filesOutput = execSync(
41 `git diff --name-status ${parentSha} ${commitSha}`,
42 { cwd: repoPath, encoding: 'utf-8' },
43 )
44
45 const lines = filesOutput.trim().split('\n').filter(Boolean)
46
47 for (const line of lines) {
48 const [status, ...pathParts] = line.split('\t')
49 const filePath = pathParts[pathParts.length - 1]
50
51 let statusType: FileDiff['status'] = 'modified'
52 let oldPath: string | undefined
53
54 if (status === 'A') {
55 statusType = 'added'
56 } else if (status === 'D') {
57 statusType = 'deleted'
58 } else if (status.startsWith('R')) {
59 statusType = 'renamed'
60 oldPath = pathParts[0]
61 }
62
63 const oldContent = getFileContentAtCommit(
64 repoPath,
65 parentSha,
66 oldPath || filePath,
67 )
68 const newContent = getFileContentAtCommit(repoPath, commitSha, filePath)
69
70 const diff = createTwoFilesPatch(
71 oldPath || filePath,
72 filePath,
73 oldContent,
74 newContent,
75 `${parentSha.slice(0, 7)} (parent)`,
76 `${commitSha.slice(0, 7)} (commit)`,
77 )
78
79 fileDiffs.push({
80 path: filePath,
81 status: statusType,
82 oldPath,
83 diff,
84 })
85 }
86
87 return fileDiffs
88}
89
90function getFullDiff(

Callers 1

processCommitFunction · 0.85

Calls 1

getFileContentAtCommitFunction · 0.85

Tested by

no test coverage detected