filterDiff reads a unified diff and returns a new reader with file entries matching any of the exclude patterns removed.
(r io.Reader, excludePatterns []string)
| 390 | // filterDiff reads a unified diff and returns a new reader with file entries |
| 391 | // matching any of the exclude patterns removed. |
| 392 | func filterDiff(r io.Reader, excludePatterns []string) (io.Reader, error) { |
| 393 | data, err := io.ReadAll(r) |
| 394 | if err != nil { |
| 395 | return nil, err |
| 396 | } |
| 397 | |
| 398 | var result bytes.Buffer |
| 399 | for _, section := range splitDiffSections(string(data)) { |
| 400 | name := extractFileName(section) |
| 401 | if name != "" && matchesAny(name, excludePatterns) { |
| 402 | continue |
| 403 | } |
| 404 | result.WriteString(section) |
| 405 | } |
| 406 | return &result, nil |
| 407 | } |
| 408 | |
| 409 | // splitDiffSections splits a unified diff string into per-file sections. |
| 410 | // Each section starts with "diff --git" and includes all content up to (but |