just a step towards #25655 and some related refactoring
Showing the changes to services/gitdiff/gitdiff.go (1 of 32 files). Show all
Unified · Split
| @@ -779,7 +779,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) { · 778 unmodified lines | |||
| 779 | for { | 779 | for { |
| 780 | lineBytes, isFragment, err = input.ReadLine() | 780 | lineBytes, isFragment, err = input.ReadLine() |
| 781 | if err != nil { | 781 | if err != nil { |
| 782 | return | 782 | return "", err |
| 783 | } | 783 | } |
| 784 | if wasFragment { | 784 | if wasFragment { |
| 785 | wasFragment = isFragment | 785 | wasFragment = isFragment |
| @@ -795,7 +795,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) { · 9 unmodified lines | |||
| 795 | var tail string | 795 | var tail string |
| 796 | tail, err = input.ReadString('\n') | 796 | tail, err = input.ReadString('\n') |
| 797 | if err != nil { | 797 | if err != nil { |
| 798 | return | 798 | return "", err |
| 799 | } | 799 | } |
| 800 | line += tail | 800 | line += tail |
| 801 | } | 801 | } |
| @@ -821,22 +821,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 19 unmodified lines | |||
| 821 | _, isFragment, err = input.ReadLine() | 821 | _, isFragment, err = input.ReadLine() |
| 822 | if err != nil { | 822 | if err != nil { |
| 823 | // Now by the definition of ReadLine this cannot be io.EOF | 823 | // Now by the definition of ReadLine this cannot be io.EOF |
| 824 | err = fmt.Errorf("unable to ReadLine: %w", err) | 824 | return nil, false, fmt.Errorf("unable to ReadLine: %w", err) |
| 825 | return | ||
| 826 | } | 825 | } |
| 827 | } | 826 | } |
| 828 | sb.Reset() | 827 | sb.Reset() |
| 829 | lineBytes, isFragment, err = input.ReadLine() | 828 | lineBytes, isFragment, err = input.ReadLine() |
| 830 | if err != nil { | 829 | if err != nil { |
| 831 | if err == io.EOF { | 830 | if err == io.EOF { |
| 832 | return | 831 | return lineBytes, isFragment, err |
| 833 | } | 832 | } |
| 834 | err = fmt.Errorf("unable to ReadLine: %w", err) | 833 | err = fmt.Errorf("unable to ReadLine: %w", err) |
| 835 | return | 834 | return nil, false, err |
| 836 | } | 835 | } |
| 837 | if lineBytes[0] == 'd' { | 836 | if lineBytes[0] == 'd' { |
| 838 | // End of hunks | 837 | // End of hunks |
| 839 | return | 838 | return lineBytes, isFragment, err |
| 840 | } | 839 | } |
| 841 | 840 | ||
| 842 | switch lineBytes[0] { | 841 | switch lineBytes[0] { |
| @@ -853,8 +852,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 10 unmodified lines | |||
| 853 | lineBytes, isFragment, err = input.ReadLine() | 852 | lineBytes, isFragment, err = input.ReadLine() |
| 854 | if err != nil { | 853 | if err != nil { |
| 855 | // Now by the definition of ReadLine this cannot be io.EOF | 854 | // Now by the definition of ReadLine this cannot be io.EOF |
| 856 | err = fmt.Errorf("unable to ReadLine: %w", err) | 855 | return nil, false, fmt.Errorf("unable to ReadLine: %w", err) |
| 857 | return | ||
| 858 | } | 856 | } |
| 859 | _, _ = sb.Write(lineBytes) | 857 | _, _ = sb.Write(lineBytes) |
| 860 | } | 858 | } |
| @@ -884,8 +882,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 23 unmodified lines | |||
| 884 | } | 882 | } |
| 885 | // This is used only to indicate that the current file does not have a terminal newline | 883 | // This is used only to indicate that the current file does not have a terminal newline |
| 886 | if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) { | 884 | if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) { |
| 887 | err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes)) | 885 | return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes)) |
| 888 | return | ||
| 889 | } | 886 | } |
| 890 | // Technically this should be the end the file! | 887 | // Technically this should be the end the file! |
| 891 | // FIXME: we should be putting a marker at the end of the file if there is no terminal new line | 888 | // FIXME: we should be putting a marker at the end of the file if there is no terminal new line |
| @@ -953,8 +950,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 61 unmodified lines | |||
| 953 | curSection.Lines = append(curSection.Lines, diffLine) | 950 | curSection.Lines = append(curSection.Lines, diffLine) |
| 954 | default: | 951 | default: |
| 955 | // This is unexpected | 952 | // This is unexpected |
| 956 | err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes)) | 953 | return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes)) |
| 957 | return | ||
| 958 | } | 954 | } |
| 959 | 955 | ||
| 960 | line := string(lineBytes) | 956 | line := string(lineBytes) |
| @@ -965,8 +961,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 4 unmodified lines | |||
| 965 | lineBytes, isFragment, err = input.ReadLine() | 961 | lineBytes, isFragment, err = input.ReadLine() |
| 966 | if err != nil { | 962 | if err != nil { |
| 967 | // Now by the definition of ReadLine this cannot be io.EOF | 963 | // Now by the definition of ReadLine this cannot be io.EOF |
| 968 | err = fmt.Errorf("unable to ReadLine: %w", err) | 964 | return lineBytes, isFragment, fmt.Errorf("unable to ReadLine: %w", err) |
| 969 | return | ||
| 970 | } | 965 | } |
| 971 | } | 966 | } |
| 972 | } | 967 | } |