Skip to content

Commit

Permalink
Use enry language type to detect special languages (go-gitea#11974)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored Jun 19, 2020
1 parent 5389b6c commit 6891b90
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions modules/git/repo_language_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ import (
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
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
func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error) {
r, err := git.PlainOpen(repo.Path)
Expand Down Expand Up @@ -95,8 +81,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err

// filter special languages unless they are the only language
if len(sizes) > 1 {
for _, language := range specialLanguages {
delete(sizes, language)
for language := range sizes {
langtype := enry.GetLanguageType(language)
if langtype != enry.Programming && langtype != enry.Markup {
delete(sizes, language)
}
}
}

Expand Down

0 comments on commit 6891b90

Please sign in to comment.