mirror of
https://github.com/go-gitea/gitea
synced 2024-08-16 20:30:48 +02:00
Improve memory usage when reaching diff limits (#2990)
Signed-off-by: Duncan Ogilvie <mr.exodia.tpodt@gmail.com>
This commit is contained in:
parent
d39b88ae88
commit
c80d147fa9
@ -252,19 +252,27 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
|
|||||||
input := bufio.NewReader(reader)
|
input := bufio.NewReader(reader)
|
||||||
isEOF := false
|
isEOF := false
|
||||||
for !isEOF {
|
for !isEOF {
|
||||||
line, err := input.ReadString('\n')
|
var linebuf bytes.Buffer
|
||||||
if err != nil {
|
for {
|
||||||
if err == io.EOF {
|
b, err := input.ReadByte()
|
||||||
isEOF = true
|
if err != nil {
|
||||||
} else {
|
if err == io.EOF {
|
||||||
return nil, fmt.Errorf("ReadString: %v", err)
|
isEOF = true
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("ReadByte: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if b == '\n' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if linebuf.Len() < maxLineCharacters {
|
||||||
|
linebuf.WriteByte(b)
|
||||||
|
} else if linebuf.Len() == maxLineCharacters {
|
||||||
|
curFile.IsIncomplete = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
line := linebuf.String()
|
||||||
if len(line) > 0 && line[len(line)-1] == '\n' {
|
|
||||||
// Remove line break.
|
|
||||||
line = line[:len(line)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(line, "+++ ") || strings.HasPrefix(line, "--- ") || len(line) == 0 {
|
if strings.HasPrefix(line, "+++ ") || strings.HasPrefix(line, "--- ") || len(line) == 0 {
|
||||||
continue
|
continue
|
||||||
@ -295,7 +303,7 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
|
|||||||
lineCount++
|
lineCount++
|
||||||
|
|
||||||
// Diff data too large, we only show the first about maxLines lines
|
// Diff data too large, we only show the first about maxLines lines
|
||||||
if curFileLinesCount >= maxLines || len(line) >= maxLineCharacters {
|
if curFileLinesCount >= maxLines {
|
||||||
curFile.IsIncomplete = true
|
curFile.IsIncomplete = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user