| 319 | } |
| 320 | |
| 321 | export function filterPatch(patch: string, options: { exclude: Set<string> }): string { |
| 322 | if (!patch.trim()) return "" |
| 323 | const blocks: string[] = [] |
| 324 | let current: string[] = [] |
| 325 | let currentFile: string | undefined |
| 326 | |
| 327 | const flush = () => { |
| 328 | if (!current.length) return |
| 329 | if (!currentFile || !options.exclude.has(currentFile)) { |
| 330 | blocks.push(current.join("\n")) |
| 331 | } |
| 332 | current = [] |
| 333 | currentFile = undefined |
| 334 | } |
| 335 | |
| 336 | for (const line of patch.split("\n")) { |
| 337 | if (line.startsWith("diff --git ")) { |
| 338 | flush() |
| 339 | current.push(line) |
| 340 | const match = line.match(/^diff --git a\/(.+?) b\/(.+)$/) |
| 341 | currentFile = match?.[2] |
| 342 | continue |
| 343 | } |
| 344 | current.push(line) |
| 345 | } |
| 346 | flush() |
| 347 | return blocks.join("\n").trim() |
| 348 | } |
| 349 | |
| 350 | export const FileDiff = z |
| 351 | .object({ |