| 192 | * @param filename File path for the diff |
| 193 | */ |
| 194 | const structuredDiffForFile = async (filename: string): Promise<StructuredDiff | null> => { |
| 195 | let fileDiffs: GitStructuredDiff |
| 196 | |
| 197 | if (config.getStructuredDiffForFile) { |
| 198 | fileDiffs = await config.getStructuredDiffForFile(config.baseSHA, config.headSHA, filename) |
| 199 | } else { |
| 200 | const diff = await getFullDiff!(config.baseSHA, config.headSHA) |
| 201 | fileDiffs = parseDiff(diff) |
| 202 | } |
| 203 | const structuredDiff = fileDiffs.find((diff) => diff.from === filename || diff.to === filename) |
| 204 | if (structuredDiff !== undefined && structuredDiff.chunks !== undefined) { |
| 205 | return { |
| 206 | chunks: structuredDiff.chunks, |
| 207 | // '/dev/null' will be in the 'from' path if the file is new. |
| 208 | fromPath: structuredDiff.from === "/dev/null" ? undefined : structuredDiff.from, |
| 209 | } |
| 210 | } else { |
| 211 | return null |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Gets the git-style diff for a single file. |