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)
| 410 | // Each section starts with "diff --git" and includes all content up to (but |
| 411 | // not including) the next "diff --git" line. |
| 412 | func 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 | |
| 431 | func extractFileName(section string) string { |
| 432 | m := diffHeaderRegexp.FindStringSubmatch(section) |