nolint:gocognit
(send func(f *File) error)
| 450 | |
| 451 | //nolint:gocognit |
| 452 | func (p *Parser) Parse(send func(f *File) error) error { |
| 453 | file := new(File) |
| 454 | currentFileLines := 0 |
| 455 | additions := 0 |
| 456 | deletions := 0 |
| 457 | |
| 458 | for !p.isEOF { |
| 459 | newLine, err := p.readLine() |
| 460 | if err != nil { |
| 461 | return err |
| 462 | } |
| 463 | |
| 464 | if len(p.buffer) == 0 { |
| 465 | p.buffer = nil |
| 466 | continue |
| 467 | } |
| 468 | |
| 469 | // Found new file |
| 470 | if bytes.HasPrefix(p.buffer, diffHead) { |
| 471 | // stream previous file |
| 472 | if !file.IsEmpty() && send != nil { |
| 473 | _, _ = p.Patch.WriteTo(&file.Patch) |
| 474 | err = send(file) |
| 475 | if err != nil { |
| 476 | return fmt.Errorf("failed to send out file: %w", err) |
| 477 | } |
| 478 | } |
| 479 | file, err = p.parseFileHeader() |
| 480 | if err != nil { |
| 481 | return err |
| 482 | } |
| 483 | |
| 484 | currentFileLines = 0 |
| 485 | continue |
| 486 | } |
| 487 | |
| 488 | if file == nil { |
| 489 | p.buffer = nil |
| 490 | continue |
| 491 | } |
| 492 | |
| 493 | if p.IncludePatch && len(p.buffer) > 0 { |
| 494 | p.Patch.Write(p.buffer) |
| 495 | if newLine { |
| 496 | p.Patch.Write([]byte{'\n'}) |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | if bytes.HasPrefix(p.buffer, []byte("Binary")) { |
| 501 | p.buffer = nil |
| 502 | file.IsBinary = true |
| 503 | continue |
| 504 | } |
| 505 | |
| 506 | // Loop until we found section header |
| 507 | if p.buffer[0] != '@' { |
| 508 | p.buffer = nil |
| 509 | continue |
no test coverage detected