summaryrefslogtreecommitdiffstats
path: root/services/gitdiff
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2023-07-07 07:31:56 +0200
committerGitHub <noreply@github.com>2023-07-07 05:31:56 +0000
commit8995046110147ae2c8c98be4e0a8c0b643ccc29c (patch)
tree94a3007199687c0a68eee5889af1619f1eebaf61 /services/gitdiff
parentb1eb1676aa95d776ff9085002641ad62e040cd93 (diff)
downloadgitea-8995046110147ae2c8c98be4e0a8c0b643ccc29c.tar.gz
gitea-8995046110147ae2c8c98be4e0a8c0b643ccc29c.zip
Less naked returns (#25713)
just a step towards #25655 and some related refactoring
Diffstat (limited to 'services/gitdiff')
-rw-r--r--services/gitdiff/gitdiff.go25
1 files changed, 10 insertions, 15 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 38283680ae..9e1db6fd43 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -779,7 +779,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
for {
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
- return
+ return "", err
}
if wasFragment {
wasFragment = isFragment
@@ -795,7 +795,7 @@ func skipToNextDiffHead(input *bufio.Reader) (line string, err error) {
var tail string
tail, err = input.ReadString('\n')
if err != nil {
- return
+ return "", err
}
line += tail
}
@@ -821,22 +821,21 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
_, isFragment, err = input.ReadLine()
if err != nil {
// Now by the definition of ReadLine this cannot be io.EOF
- err = fmt.Errorf("unable to ReadLine: %w", err)
- return
+ return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
}
}
sb.Reset()
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
if err == io.EOF {
- return
+ return lineBytes, isFragment, err
}
err = fmt.Errorf("unable to ReadLine: %w", err)
- return
+ return nil, false, err
}
if lineBytes[0] == 'd' {
// End of hunks
- return
+ return lineBytes, isFragment, err
}
switch lineBytes[0] {
@@ -853,8 +852,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
// Now by the definition of ReadLine this cannot be io.EOF
- err = fmt.Errorf("unable to ReadLine: %w", err)
- return
+ return nil, false, fmt.Errorf("unable to ReadLine: %w", err)
}
_, _ = sb.Write(lineBytes)
}
@@ -884,8 +882,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
}
// This is used only to indicate that the current file does not have a terminal newline
if !bytes.Equal(lineBytes, []byte("\\ No newline at end of file")) {
- err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
- return
+ return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
}
// Technically this should be the end the file!
// 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
curSection.Lines = append(curSection.Lines, diffLine)
default:
// This is unexpected
- err = fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
- return
+ return nil, false, fmt.Errorf("unexpected line in hunk: %s", string(lineBytes))
}
line := string(lineBytes)
@@ -965,8 +961,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
// Now by the definition of ReadLine this cannot be io.EOF
- err = fmt.Errorf("unable to ReadLine: %w", err)
- return
+ return lineBytes, isFragment, fmt.Errorf("unable to ReadLine: %w", err)
}
}
}