aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-06-19 11:07:56 +0300
committerGitHub <noreply@github.com>2020-06-19 11:07:56 +0300
commit5389b6cde1895bf145b7a830c9de2e503e7fd73d (patch)
tree71c46d7e8b1856dc820695ff61801ac78b6ab019 /modules/git
parent92a05f87f070b0d2a1e9eb53072e00f0f1c3b69a (diff)
downloadgitea-5389b6cde1895bf145b7a830c9de2e503e7fd73d.tar.gz
gitea-5389b6cde1895bf145b7a830c9de2e503e7fd73d.zip
For language detection do not try to analyze big files by content (#11971)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/repo_language_stats.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/git/repo_language_stats.go b/modules/git/repo_language_stats.go
index 06d7d6aba0..06ff704497 100644
--- a/modules/git/repo_language_stats.go
+++ b/modules/git/repo_language_stats.go
@@ -17,7 +17,8 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
)
-const fileSizeLimit int64 = 16 * 1024 * 1024
+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
@@ -62,8 +63,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
return nil
}
- // If content can not be read just do detection by filename
- content, _ := readFile(f, fileSizeLimit)
+ // If content can not be read or file is too big just do detection by filename
+ var content []byte
+ if f.Size <= bigFileSize {
+ content, _ = readFile(f, fileSizeLimit)
+ }
if enry.IsGenerated(f.Name, content) {
return nil
}