diff options
author | Lauris BH <lauris@nix.lv> | 2020-02-20 21:53:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 16:53:55 -0300 |
commit | 3c45cf8494fcd29e1a99b0ee6f253808eb607053 (patch) | |
tree | cd0e6347bcd2bfc42c18408169a8757ca1dda920 /modules/git/repo_language_stats.go | |
parent | efbd7ca39bde69ff84d4b309bee99edfe2977521 (diff) | |
download | gitea-3c45cf8494fcd29e1a99b0ee6f253808eb607053.tar.gz gitea-3c45cf8494fcd29e1a99b0ee6f253808eb607053.zip |
Add detected file language to code search (#10256)
Move langauge detection to separate module to be more reusable
Add option to disable vendored file exclusion from file search
Allways show all language stats for search
Diffstat (limited to 'modules/git/repo_language_stats.go')
-rw-r--r-- | modules/git/repo_language_stats.go | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go index ffe6dd0848..305fb97795 100644 --- a/modules/git/repo_language_stats.go +++ b/modules/git/repo_language_stats.go @@ -9,7 +9,8 @@ import ( "io" "io/ioutil" "math" - "path/filepath" + + "code.gitea.io/gitea/modules/analyze" "github.com/src-d/enry/v2" "gopkg.in/src-d/go-git.v4" @@ -51,25 +52,15 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, e // TODO: Use .gitattributes file for linguist overrides - language, ok := enry.GetLanguageByExtension(f.Name) - if !ok { - if language, ok = enry.GetLanguageByFilename(f.Name); !ok { - content, err := readFile(f, fileSizeLimit) - if err != nil { - return nil - } - - language = enry.GetLanguage(filepath.Base(f.Name), content) - if language == enry.OtherLanguage { - return nil - } - } + language := analyze.GetCodeLanguageWithCallback(f.Name, func() ([]byte, error) { + return readFile(f, fileSizeLimit) + }) + if language == enry.OtherLanguage || language == "" { + return nil } - if language != "" { - sizes[language] += f.Size - total += f.Size - } + sizes[language] += f.Size + total += f.Size return nil }) |