diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go index 8ff8fa20c1f6a..2e5a0534c4510 100644 --- a/modules/git/repo_language_stats.go +++ b/modules/git/repo_language_stats.go @@ -20,6 +20,18 @@ import ( const fileSizeLimit int64 = 16 * 1024 * 1024 +// specialLanguages defines list of languages that are excluded from the calculation +// unless they are the only language present in repository. Only languages which under +// normal circumstances are not considered to be code should be listed here. +var specialLanguages = []string{ + "YAML", + "JSON", + "SVG", + "Text", + "Markdown", + "TOML", +} + // GetLanguageStats calculates language stats for git repository at specified commit func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, error) { r, err := git.PlainOpen(repo.Path) @@ -72,6 +84,14 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, e return nil, err } + // filter special languages unless they are the only language + if len(sizes) > 1 { + for _, language := range specialLanguages { + total -= sizes[language] + delete(sizes, language) + } + } + stats := make(map[string]float32) var otherPerc float32 = 100 for language, size := range sizes {