(hunk *Hunk)
| 271 | } |
| 272 | |
| 273 | func (r *Repository) splitHunkInternal(hunk *Hunk) []Hunk { |
| 274 | if hunk.Type != HunkTypeHunk { |
| 275 | return []Hunk{*hunk} |
| 276 | } |
| 277 | |
| 278 | // Find the first context line after changes that has more changes after it |
| 279 | var splitPoint int = -1 |
| 280 | addDel := false |
| 281 | |
| 282 | for i := 1; i < len(hunk.Text); i++ { |
| 283 | line := hunk.Text[i] |
| 284 | if strings.HasPrefix(line, "\\") { |
| 285 | continue |
| 286 | } |
| 287 | |
| 288 | if strings.HasPrefix(line, " ") { |
| 289 | // Context line |
| 290 | if addDel { |
| 291 | // Check if there are more changes after this context line |
| 292 | hasMoreChanges := false |
| 293 | for j := i + 1; j < len(hunk.Text); j++ { |
| 294 | nextLine := hunk.Text[j] |
| 295 | if strings.HasPrefix(nextLine, "+") || strings.HasPrefix(nextLine, "-") { |
| 296 | hasMoreChanges = true |
| 297 | break |
| 298 | } |
| 299 | } |
| 300 | if hasMoreChanges { |
| 301 | splitPoint = i |
| 302 | break |
| 303 | } |
| 304 | } |
| 305 | } else if strings.HasPrefix(line, "+") || strings.HasPrefix(line, "-") { |
| 306 | addDel = true |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if splitPoint == -1 { |
| 311 | return []Hunk{*hunk} |
| 312 | } |
| 313 | |
| 314 | // Create exactly 2 splits like Perl version |
| 315 | var splits []Hunk |
| 316 | |
| 317 | // Split 1: from start to splitPoint (inclusive) |
| 318 | split1 := Hunk{ |
| 319 | Type: HunkTypeHunk, |
| 320 | Text: []string{}, |
| 321 | Display: []string{}, |
| 322 | OldLine: hunk.OldLine, |
| 323 | NewLine: hunk.NewLine, |
| 324 | OldCnt: 0, |
| 325 | NewCnt: 0, |
| 326 | } |
| 327 | |
| 328 | for i := 1; i <= splitPoint; i++ { |
| 329 | line := hunk.Text[i] |
| 330 | displayLine := line |
no test coverage detected