Skip to content

Commit 3e8618a

Browse files
authored
For language detection do not try to analyze big files by content (#11971) (#11975)
1 parent 3a2679d commit 3e8618a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/git/repo_language_stats.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
"github.com/go-git/go-git/v5/plumbing/object"
1818
)
1919

20-
const fileSizeLimit int64 = 16 * 1024 * 1024
20+
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
21+
const bigFileSize int64 = 1024 * 1024 // 1 MiB
2122

2223
// specialLanguages defines list of languages that are excluded from the calculation
2324
// 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
6263
return nil
6364
}
6465

65-
// If content can not be read just do detection by filename
66-
content, _ := readFile(f, fileSizeLimit)
66+
// If content can not be read or file is too big just do detection by filename
67+
var content []byte
68+
if f.Size <= bigFileSize {
69+
content, _ = readFile(f, fileSizeLimit)
70+
}
6771
if enry.IsGenerated(f.Name, content) {
6872
return nil
6973
}

0 commit comments

Comments
 (0)