History

Less naked returns (#25713)

just a step towards #25655 and some related refactoring

6543 committed 3 years ago

Commit 89950461 parent b1eb16732 files · +254 −239Browse files

Showing the changes to services/gitdiff/gitdiff.go (1 of 32 files). Show all

Unified · Split

services/gitdiff/gitdiff.go+10−15
@@ -779,7 +779,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) { · 778 unmodified lines
779779 for {
780780 lineBytes, isFragment, err = input.ReadLine()
781781 if err != nil {
782− return
782+ return "", err
783783 }
784784 if wasFragment {
785785 wasFragment = isFragment
@@ -795,7 +795,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) { · 9 unmodified lines
795795 var tail string
796796 tail, err = input.ReadString('\n')
797797 if err != nil {
798− return
798+ return "", err
799799 }
800800 line += tail
801801 }
@@ -821,22 +821,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 19 unmodified lines
821821 _, isFragment, err = input.ReadLine()
822822 if err != nil {
823823 // Now by the definition of ReadLine this cannot be io.EOF
824− err = fmt.Errorf("unable to ReadLine: %w", err)
825− return
824+ return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
826825 }
827826 }
828827 sb.Reset()
829828 lineBytes, isFragment, err = input.ReadLine()
830829 if err != nil {
831830 if err == io.EOF {
832− return
831+ return lineBytes, isFragment, err
833832 }
834833 err = fmt.Errorf("unable to ReadLine: %w", err)
835− return
834+ return nil, false, err
836835 }
837836 if lineBytes[0] == 'd' {
838837 // End of hunks
839− return
838+ return lineBytes, isFragment, err
840839 }
841840
842841 switch lineBytes[0] {
@@ -853,8 +852,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 10 unmodified lines
853852 lineBytes, isFragment, err = input.ReadLine()
854853 if err != nil {
855854 // Now by the definition of ReadLine this cannot be io.EOF
856− err = fmt.Errorf("unable to ReadLine: %w", err)
857− return
855+ return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
858856 }
859857 _, _ = sb.Write(lineBytes)
860858 }
@@ -884,8 +882,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 23 unmodified lines
884882 }
885883 // This is used only to indicate that the current file does not have a terminal newline
886884 if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) {
887− err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
888− return
885+ return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
889886 }
890887 // Technically this should be the end the file!
891888 // 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
953950 curSection.Lines = append(curSection.Lines, diffLine)
954951 default:
955952 // This is unexpected
956− err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
957− return
953+ return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
958954 }
959955
960956 line := string(lineBytes)
@@ -965,8 +961,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 4 unmodified lines
965961 lineBytes, isFragment, err = input.ReadLine()
966962 if err != nil {
967963 // Now by the definition of ReadLine this cannot be io.EOF
968− err = fmt.Errorf("unable to ReadLine: %w", err)
969− return
964+ return lineBytes, isFragment, fmt.Errorf("unable to ReadLine: %w", err)
970965 }
971966 }
972967 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t