MCPcopy Create free account
hub / github.com/cli/cli / filterDiff

Function filterDiff

pkg/cmd/pr/diff/diff.go:363–378  ·  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

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