MCPcopy Index your code
hub / github.com/cli/cli / filterDiff

Function filterDiff

pkg/cmd/pr/diff/diff.go:392–407  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

390// filterDiff reads a unified diff and returns a new reader with file entries
391// matching any of the exclude patterns removed.
392func 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

Callers 2

diffRunFunction · 0.85
Test_filterDiffFunction · 0.85

Calls 3

splitDiffSectionsFunction · 0.85
extractFileNameFunction · 0.85
matchesAnyFunction · 0.85

Tested by 1

Test_filterDiffFunction · 0.68