Skip to content

Commit

Permalink
For language detection do not try to analyze big files by content (go…
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored Jun 19, 2020
1 parent 92a05f8 commit 5389b6c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/git/repo_language_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5389b6c

Please sign in to comment.