Refactor git attributes (#29356)

This commit is contained in:
KN4CK3R 2024-02-24 19:46:49 +01:00 committed by GitHub
parent 98ab9445d1
commit 4197e28100
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 101 additions and 100 deletions

View file

@ -8,7 +8,6 @@ package git
import (
"bytes"
"io"
"strings"
"code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/optional"
@ -66,36 +65,27 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
if checker != nil {
attrs, err := checker.CheckPath(f.Name)
if err == nil {
isVendored = attributeToBool(attrs, "linguist-vendored")
isVendored = AttributeToBool(attrs, AttributeLinguistVendored)
if isVendored.ValueOrDefault(false) {
return nil
}
isGenerated = attributeToBool(attrs, "linguist-generated")
isGenerated = AttributeToBool(attrs, AttributeLinguistGenerated)
if isGenerated.ValueOrDefault(false) {
return nil
}
isDocumentation = attributeToBool(attrs, "linguist-documentation")
isDocumentation = AttributeToBool(attrs, AttributeLinguistDocumentation)
if isDocumentation.ValueOrDefault(false) {
return nil
}
isDetectable = attributeToBool(attrs, "linguist-detectable")
isDetectable = AttributeToBool(attrs, AttributeLinguistDetectable)
if !isDetectable.ValueOrDefault(true) {
return nil
}
hasLanguage := attributeToString(attrs, "linguist-language")
if hasLanguage.Value() == "" {
hasLanguage = attributeToString(attrs, "gitlab-language")
if hasLanguage.Has() {
language := hasLanguage.Value()
if idx := strings.IndexByte(language, '?'); idx >= 0 {
hasLanguage = optional.Some(language[:idx])
}
}
}
hasLanguage := TryReadLanguageAttribute(attrs)
if hasLanguage.Value() != "" {
language := hasLanguage.Value()