|
|
|
@ -44,7 +44,15 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
|
|
|
|
checker, deferable := repo.CheckAttributeReader(commitID)
|
|
|
|
|
defer deferable()
|
|
|
|
|
|
|
|
|
|
// sizes contains the current calculated size of all files by language
|
|
|
|
|
sizes := make(map[string]int64)
|
|
|
|
|
// by default we will only count the sizes of programming languages or markup languages
|
|
|
|
|
// unless they are explicitly set using linguist-language
|
|
|
|
|
includedLanguage := map[string]bool{}
|
|
|
|
|
// or if there's only one language in the repository
|
|
|
|
|
firstExcludedLanguage := ""
|
|
|
|
|
firstExcludedLanguageSize := int64(0)
|
|
|
|
|
|
|
|
|
|
err = tree.Files().ForEach(func(f *object.File) error {
|
|
|
|
|
if f.Size == 0 {
|
|
|
|
|
return nil
|
|
|
|
@ -75,8 +83,8 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
|
|
|
|
language = group
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this language will always be added to the size
|
|
|
|
|
sizes[language] += f.Size
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
} else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" {
|
|
|
|
|
// strip off a ? if present
|
|
|
|
@ -90,6 +98,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
|
|
|
|
language = group
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this language will always be added to the size
|
|
|
|
|
sizes[language] += f.Size
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@ -124,7 +133,18 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
|
|
|
|
language = group
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sizes[language] += f.Size
|
|
|
|
|
included, checked := includedLanguage[language]
|
|
|
|
|
if !checked {
|
|
|
|
|
langtype := enry.GetLanguageType(language)
|
|
|
|
|
included = langtype == enry.Programming || langtype == enry.Markup
|
|
|
|
|
includedLanguage[language] = included
|
|
|
|
|
}
|
|
|
|
|
if included {
|
|
|
|
|
sizes[language] += f.Size
|
|
|
|
|
} else if len(sizes) == 0 && (firstExcludedLanguage == "" || firstExcludedLanguage == language) {
|
|
|
|
|
firstExcludedLanguage = language
|
|
|
|
|
firstExcludedLanguageSize += f.Size
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
@ -132,14 +152,9 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// filter special languages unless they are the only language
|
|
|
|
|
if len(sizes) > 1 {
|
|
|
|
|
for language := range sizes {
|
|
|
|
|
langtype := enry.GetLanguageType(language)
|
|
|
|
|
if langtype != enry.Programming && langtype != enry.Markup {
|
|
|
|
|
delete(sizes, language)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If there are no included languages add the first excluded language
|
|
|
|
|
if len(sizes) == 0 && firstExcludedLanguage != "" {
|
|
|
|
|
sizes[firstExcludedLanguage] = firstExcludedLanguageSize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sizes, nil
|
|
|
|
|