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

Function splitDiffSections

pkg/cmd/pr/diff/diff.go:383–400  ·  view source on GitHub ↗

splitDiffSections splits a unified diff string into per-file sections. Each section starts with "diff --git" and includes all content up to (but not including) the next "diff --git" line.

(diff string)

Source from the content-addressed store, hash-verified

381// Each section starts with "diff --git" and includes all content up to (but
382// not including) the next "diff --git" line.
383func splitDiffSections(diff string) []string {
384 marker := "\ndiff --git "
385 parts := strings.Split(diff, marker)
386 if len(parts) == 1 {
387 return []string{diff}
388 }
389 sections := make([]string, 0, len(parts))
390 for i, p := range parts {
391 if i == 0 {
392 if len(p) > 0 {
393 sections = append(sections, p+"\n")
394 }
395 } else {
396 sections = append(sections, "diff --git "+p)
397 }
398 }
399 return sections
400}
401
402func extractFileName(section string) string {
403 m := diffHeaderRegexp.FindStringSubmatch(section)

Callers 1

filterDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected