0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-09-12 14:56:30 +02:00

Allow foreachref parser to grow its buffer (#35365) (#35376)

Backport #35365 by meyfa-lawo

Signed-off-by: Fabian Meyer <fabian.meyer@lawo.com>
Co-authored-by: Fabian Meyer <fabian.meyer@lawo.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot 2025-08-29 10:29:34 +08:00 committed by GitHub
parent 8f89e1e174
commit 1b8efb6fc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,6 +30,10 @@ type Parser struct {
func NewParser(r io.Reader, format Format) *Parser {
scanner := bufio.NewScanner(r)
// default MaxScanTokenSize = 64 kiB may be too small for some references,
// so allow the buffer to grow up to 4x if needed
scanner.Buffer(nil, 4*bufio.MaxScanTokenSize)
// in addition to the reference delimiter we specified in the --format,
// `git for-each-ref` will always add a newline after every reference.
refDelim := make([]byte, 0, len(format.refDelim)+1)
@ -70,6 +74,9 @@ func NewParser(r io.Reader, format Format) *Parser {
// { "objecttype": "tag", "refname:short": "v1.16.4", "object": "f460b7543ed500e49c133c2cd85c8c55ee9dbe27" }
func (p *Parser) Next() map[string]string {
if !p.scanner.Scan() {
if err := p.scanner.Err(); err != nil {
p.err = err
}
return nil
}
fields, err := p.parseRef(p.scanner.Text())