Use enry language type to detect special languages (#11974)
This commit is contained in:
parent
5389b6cde1
commit
6891b90303
1 changed files with 5 additions and 16 deletions
|
@ -20,20 +20,6 @@ import (
|
||||||
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
|
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
|
||||||
const bigFileSize int64 = 1024 * 1024 // 1 MiB
|
const bigFileSize int64 = 1024 * 1024 // 1 MiB
|
||||||
|
|
||||||
// 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{
|
|
||||||
"XML",
|
|
||||||
"JSON",
|
|
||||||
"TOML",
|
|
||||||
"YAML",
|
|
||||||
"INI",
|
|
||||||
"SVG",
|
|
||||||
"Text",
|
|
||||||
"Markdown",
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLanguageStats calculates language stats for git repository at specified commit
|
// GetLanguageStats calculates language stats for git repository at specified commit
|
||||||
func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error) {
|
func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error) {
|
||||||
r, err := git.PlainOpen(repo.Path)
|
r, err := git.PlainOpen(repo.Path)
|
||||||
|
@ -95,10 +81,13 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
|
||||||
|
|
||||||
// filter special languages unless they are the only language
|
// filter special languages unless they are the only language
|
||||||
if len(sizes) > 1 {
|
if len(sizes) > 1 {
|
||||||
for _, language := range specialLanguages {
|
for language := range sizes {
|
||||||
|
langtype := enry.GetLanguageType(language)
|
||||||
|
if langtype != enry.Programming && langtype != enry.Markup {
|
||||||
delete(sizes, language)
|
delete(sizes, language)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sizes, nil
|
return sizes, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue