mirror of
https://github.com/go-gitea/gitea
synced 2024-10-19 20:10:10 +02:00
remove GetBlobAll
This commit is contained in:
parent
c831ee31bf
commit
ae27d02aa8
@ -168,16 +168,16 @@ func detectLicenseByEntry(file *git.TreeEntry) ([]string, error) {
|
||||
}
|
||||
|
||||
blob := file.Blob()
|
||||
contentBuf, err := blob.GetBlobAll()
|
||||
content, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetBlobAll: %w", err)
|
||||
}
|
||||
return detectLicense(contentBuf), nil
|
||||
return detectLicense(content), nil
|
||||
}
|
||||
|
||||
// detectLicense returns the licenses detected by the given content buff
|
||||
func detectLicense(buf []byte) []string {
|
||||
if len(buf) == 0 {
|
||||
func detectLicense(content string) []string {
|
||||
if len(content) == 0 {
|
||||
return nil
|
||||
}
|
||||
if classifier == nil {
|
||||
@ -185,7 +185,11 @@ func detectLicense(buf []byte) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
matches := classifier.Match(buf)
|
||||
matches, err := classifier.MatchFrom(strings.NewReader(content))
|
||||
if err != nil {
|
||||
log.Error("licenseclassifier.MatchFrom: %v", err)
|
||||
return nil
|
||||
}
|
||||
var results []string
|
||||
for _, r := range matches.Matches {
|
||||
if r.MatchType == "License" {
|
||||
|
@ -34,17 +34,6 @@ func (b *Blob) GetBlobContent(limit int64) (string, error) {
|
||||
return string(buf), err
|
||||
}
|
||||
|
||||
// GetBlobAll Gets the all content of the blob as bytes
|
||||
func (b *Blob) GetBlobAll() ([]byte, error) {
|
||||
dataRc, err := b.DataAsync()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf, _ := io.ReadAll(dataRc)
|
||||
_ = dataRc.Close()
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// GetBlobLineCount gets line count of the blob
|
||||
func (b *Blob) GetBlobLineCount() (int, error) {
|
||||
reader, err := b.DataAsync()
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/options"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
licenseclassifier "github.com/google/licenseclassifier/v2"
|
||||
@ -263,16 +264,16 @@ func detectLicenseByEntry(file *git.TreeEntry) ([]string, error) {
|
||||
}
|
||||
|
||||
blob := file.Blob()
|
||||
contentBuf, err := blob.GetBlobAll()
|
||||
content, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetBlobAll: %w", err)
|
||||
}
|
||||
return detectLicense(contentBuf), nil
|
||||
return detectLicense(content), nil
|
||||
}
|
||||
|
||||
// detectLicense returns the licenses detected by the given content buff
|
||||
func detectLicense(buf []byte) []string {
|
||||
if len(buf) == 0 {
|
||||
func detectLicense(content string) []string {
|
||||
if len(content) == 0 {
|
||||
return nil
|
||||
}
|
||||
if classifier == nil {
|
||||
@ -280,7 +281,11 @@ func detectLicense(buf []byte) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
matches := classifier.Match(buf)
|
||||
matches, err := classifier.MatchFrom(strings.NewReader(content))
|
||||
if err != nil {
|
||||
log.Error("licenseclassifier.MatchFrom: %v", err)
|
||||
return nil
|
||||
}
|
||||
var results []string
|
||||
for _, r := range matches.Matches {
|
||||
if r.MatchType == "License" {
|
||||
|
Loading…
Reference in New Issue
Block a user