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

Function splitDiffSections

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

410// Each section starts with "diff --git" and includes all content up to (but
411// not including) the next "diff --git" line.
412func splitDiffSections(diff string) []string {
413 marker := "\ndiff --git "
414 parts := strings.Split(diff, marker)
415 if len(parts) == 1 {
416 return []string{diff}
417 }
418 sections := make([]string, 0, len(parts))
419 for i, p := range parts {
420 if i == 0 {
421 if len(p) > 0 {
422 sections = append(sections, p+"\n")
423 }
424 } else {
425 sections = append(sections, "diff --git "+p)
426 }
427 }
428 return sections
429}
430
431func extractFileName(section string) string {
432 m := diffHeaderRegexp.FindStringSubmatch(section)

Callers 1

filterDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected