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)
| 364 | // filterDiff reads a unified diff and returns a new reader with file entries |
| 365 | // matching any of the exclude patterns removed. |
| 366 | func filterDiff(r io.Reader, excludePatterns []string) (io.Reader, error) { |
| 367 | data, err := io.ReadAll(r) |
| 368 | if err != nil { |
| 369 | return nil, err |
| 370 | } |
| 371 | |
| 372 | var result bytes.Buffer |
| 373 | for _, section := range splitDiffSections(string(data)) { |
| 374 | name := extractFileName(section) |
| 375 | if name != "" && matchesAny(name, excludePatterns) { |
| 376 | continue |
| 377 | } |
| 378 | result.WriteString(section) |
| 379 | } |
| 380 | return &result, nil |
| 381 | } |
| 382 | |
| 383 | // splitDiffSections splits a unified diff string into per-file sections. |
| 384 | // Each section starts with "diff --git" and includes all content up to (but |