aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_language_stats.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-02-20 21:53:55 +0200
committerGitHub <noreply@github.com>2020-02-20 16:53:55 -0300
commit3c45cf8494fcd29e1a99b0ee6f253808eb607053 (patch)
treecd0e6347bcd2bfc42c18408169a8757ca1dda920 /modules/git/repo_language_stats.go
parentefbd7ca39bde69ff84d4b309bee99edfe2977521 (diff)
downloadgitea-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.go27
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
})