Refactor parseSignatureFromCommitLine (#29054)

Replace #28849. Thanks to @yp05327 for the looking into the problem.
Fix #28840

The old behavior of newSignatureFromCommitline is not right. The new
parseSignatureFromCommitLine:

1. never fails
2. only accept one format (if there is any other, it could be easily added)

And add some tests.
This commit is contained in:
wxiaoguang 2024-02-09 11:02:53 +08:00 committed by GitHub
parent da2f03750f
commit a24e1da7e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 104 additions and 149 deletions

View file

@ -7,6 +7,8 @@ import (
"bytes"
"sort"
"strings"
"code.gitea.io/gitea/modules/util"
)
const (
@ -59,11 +61,7 @@ l:
// A commit can have one or more parents
tag.Type = string(line[spacepos+1:])
case "tagger":
sig, err := newSignatureFromCommitline(line[spacepos+1:])
if err != nil {
return nil, err
}
tag.Tagger = sig
tag.Tagger = parseSignatureFromCommitLine(util.UnsafeBytesToString(line[spacepos+1:]))
}
nextline += eol + 1
case eol == 0: