@@ -17,21 +17,8 @@ import (
17
17
"github.com/go-git/go-git/v5/plumbing/object"
18
18
)
19
19
20
- const fileSizeLimit int64 = 16 * 1024 * 1024
21
-
22
- // specialLanguages defines list of languages that are excluded from the calculation
23
- // unless they are the only language present in repository. Only languages which under
24
- // normal circumstances are not considered to be code should be listed here.
25
- var specialLanguages = []string {
26
- "XML" ,
27
- "JSON" ,
28
- "TOML" ,
29
- "YAML" ,
30
- "INI" ,
31
- "SVG" ,
32
- "Text" ,
33
- "Markdown" ,
34
- }
20
+ const fileSizeLimit int64 = 16 * 1024 // 16 KiB
21
+ const bigFileSize int64 = 1024 * 1024 // 1 MiB
35
22
36
23
// GetLanguageStats calculates language stats for git repository at specified commit
37
24
func (repo * Repository ) GetLanguageStats (commitID string ) (map [string ]int64 , error ) {
@@ -62,8 +49,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
62
49
return nil
63
50
}
64
51
65
- // If content can not be read just do detection by filename
66
- content , _ := readFile (f , fileSizeLimit )
52
+ // If content can not be read or file is too big just do detection by filename
53
+ var content []byte
54
+ if f .Size <= bigFileSize {
55
+ content , _ = readFile (f , fileSizeLimit )
56
+ }
67
57
if enry .IsGenerated (f .Name , content ) {
68
58
return nil
69
59
}
@@ -91,8 +81,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
91
81
92
82
// filter special languages unless they are the only language
93
83
if len (sizes ) > 1 {
94
- for _ , language := range specialLanguages {
95
- delete (sizes , language )
84
+ for language := range sizes {
85
+ langtype := enry .GetLanguageType (language )
86
+ if langtype != enry .Programming && langtype != enry .Markup {
87
+ delete (sizes , language )
88
+ }
96
89
}
97
90
}
98
91
0 commit comments