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

Function filterDiff

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

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

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