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