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

Function splitDiffSections

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

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

Callers 1

filterDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected