Skip to content

Exclude generated files from language statistics (#11653) #11670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ require (
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
github.com/gliderlabs/ssh v0.2.2
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
github.com/go-enry/go-enry/v2 v2.3.0
github.com/go-enry/go-enry/v2 v2.5.2
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.0.0
github.com/go-openapi/jsonreference v0.19.3 // indirect
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -193,10 +193,10 @@ github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a h1:FQqo
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 h1:gclg6gY70GLy3PbkQ1AERPfmLMMagS60DKF78eWwLn8=
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/go-enry/go-enry/v2 v2.3.0 h1:o8KwgY6uSplysrIpj+Y42J/xGPp90ogVpxE2Z3s8Unk=
github.com/go-enry/go-enry/v2 v2.3.0/go.mod h1:+xFJwbqWi15bvqFHb2ELUWVRKFQtwB61+sDrkvvxxGI=
github.com/go-enry/go-oniguruma v1.2.0 h1:oBO9XC1IDT9+AoWW5oFsa/7gFeOPacEqDbyXZKWXuDs=
github.com/go-enry/go-oniguruma v1.2.0/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
github.com/go-enry/go-enry/v2 v2.5.2 h1:3f3PFAO6JitWkPi1GQ5/m6Xu4gNL1U5soJ8QaYqJ0YQ=
github.com/go-enry/go-enry/v2 v2.5.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
@@ -616,8 +616,6 @@ github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW
github.com/tinylib/msgp v1.1.2 h1:gWmO7n0Ys2RBEb7GPYB9Ujq8Mk5p2U08lRnmMcGy6BQ=
github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/toqueteos/trie v1.0.0 h1:8i6pXxNUXNRAqP246iibb7w/pSFquNTQ+uNfriG7vlk=
github.com/toqueteos/trie v1.0.0/go.mod h1:Ywk48QhEqhU1+DwhMkJ2x7eeGxDHiGkAdc9+0DYcbsM=
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/tstranex/u2f v1.0.0 h1:HhJkSzDDlVSVIVt7pDJwCHQj67k7A5EeBgPmeD+pVsQ=
@@ -876,8 +874,6 @@ gopkg.in/testfixtures.v2 v2.5.0 h1:N08B7l2GzFQenyYbzqthDnKAA+cmb17iAZhhFxr7JHw=
gopkg.in/testfixtures.v2 v2.5.0/go.mod h1:vyAq+MYCgNpR29qitQdLZhdbLFf4mR/2MFJRFoQZZ2M=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/toqueteos/substring.v1 v1.0.2 h1:urLqCeMm6x/eTuQa1oZerNw8N1KNOIp5hD5kGL7lFsE=
gopkg.in/toqueteos/substring.v1 v1.0.2/go.mod h1:Eb2Z1UYehlVK8LYW2WBVR2rwbujsz3aX8XDrM1vbNew=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
14 changes: 3 additions & 11 deletions modules/analyze/code_langauge.go
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ import (
"github.com/go-enry/go-enry/v2"
)

// GetCodeLanguageWithCallback detects code language based on file name and content using callback
func GetCodeLanguageWithCallback(filename string, contentFunc func() ([]byte, error)) string {
// GetCodeLanguage detects code language based on file name and content
func GetCodeLanguage(filename string, content []byte) string {
if language, ok := enry.GetLanguageByExtension(filename); ok {
return language
}
@@ -20,17 +20,9 @@ func GetCodeLanguageWithCallback(filename string, contentFunc func() ([]byte, er
return language
}

content, err := contentFunc()
if err != nil {
if len(content) == 0 {
return enry.OtherLanguage
}

return enry.GetLanguage(filepath.Base(filename), content)
}

// GetCodeLanguage detects code language based on file name and content
func GetCodeLanguage(filename string, content []byte) string {
return GetCodeLanguageWithCallback(filename, func() ([]byte, error) {
return content, nil
})
}
10 changes: 7 additions & 3 deletions modules/git/repo_language_stats.go
Original file line number Diff line number Diff line change
@@ -50,11 +50,15 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]float32, e
return nil
}

// If content can not be read just do detection by filename
content, _ := readFile(f, fileSizeLimit)
if enry.IsGenerated(f.Name, content) {
return nil
}

// TODO: Use .gitattributes file for linguist overrides

language := analyze.GetCodeLanguageWithCallback(f.Name, func() ([]byte, error) {
return readFile(f, fileSizeLimit)
})
language := analyze.GetCodeLanguage(f.Name, content)
if language == enry.OtherLanguage || language == "" {
return nil
}
176 changes: 90 additions & 86 deletions vendor/github.com/go-enry/go-enry/v2/README.md

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions vendor/github.com/go-enry/go-enry/v2/common.go
40 changes: 20 additions & 20 deletions vendor/github.com/go-enry/go-enry/v2/data/documentation.go
823 changes: 823 additions & 0 deletions vendor/github.com/go-enry/go-enry/v2/data/generated.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions vendor/github.com/go-enry/go-enry/v2/data/test.go
326 changes: 163 additions & 163 deletions vendor/github.com/go-enry/go-enry/v2/data/vendor.go
4 changes: 1 addition & 3 deletions vendor/github.com/go-enry/go-enry/v2/go.mod
6 changes: 2 additions & 4 deletions vendor/github.com/go-enry/go-enry/v2/go.sum
53 changes: 49 additions & 4 deletions vendor/github.com/go-enry/go-enry/v2/utils.go
22 changes: 15 additions & 7 deletions vendor/github.com/go-enry/go-oniguruma/chelper.c
8 changes: 4 additions & 4 deletions vendor/github.com/go-enry/go-oniguruma/chelper.h
401 changes: 194 additions & 207 deletions vendor/github.com/go-enry/go-oniguruma/regex.go

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions vendor/github.com/toqueteos/trie/LICENSE.txt

This file was deleted.

7 changes: 0 additions & 7 deletions vendor/github.com/toqueteos/trie/README.md

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/toqueteos/trie/go.mod

This file was deleted.

102 changes: 0 additions & 102 deletions vendor/github.com/toqueteos/trie/trie.go

This file was deleted.

24 changes: 0 additions & 24 deletions vendor/gopkg.in/toqueteos/substring.v1/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions vendor/gopkg.in/toqueteos/substring.v1/.travis.yml

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/gopkg.in/toqueteos/substring.v1/LICENSE

This file was deleted.

80 changes: 0 additions & 80 deletions vendor/gopkg.in/toqueteos/substring.v1/README.md

This file was deleted.

229 changes: 0 additions & 229 deletions vendor/gopkg.in/toqueteos/substring.v1/bytes.go

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/gopkg.in/toqueteos/substring.v1/lib.go

This file was deleted.

216 changes: 0 additions & 216 deletions vendor/gopkg.in/toqueteos/substring.v1/string.go

This file was deleted.

8 changes: 2 additions & 6 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -202,15 +202,15 @@ github.com/gliderlabs/ssh
# github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a
## explicit
github.com/glycerine/go-unsnap-stream
# github.com/go-enry/go-enry/v2 v2.3.0
# github.com/go-enry/go-enry/v2 v2.5.2
## explicit
github.com/go-enry/go-enry/v2
github.com/go-enry/go-enry/v2/data
github.com/go-enry/go-enry/v2/data/rule
github.com/go-enry/go-enry/v2/internal/tokenizer
github.com/go-enry/go-enry/v2/internal/tokenizer/flex
github.com/go-enry/go-enry/v2/regex
# github.com/go-enry/go-oniguruma v1.2.0
# github.com/go-enry/go-oniguruma v1.2.1
github.com/go-enry/go-oniguruma
# github.com/go-git/gcfg v1.5.0
github.com/go-git/gcfg
@@ -614,8 +614,6 @@ github.com/syndtr/goleveldb/leveldb/util
# github.com/tinylib/msgp v1.1.2
## explicit
github.com/tinylib/msgp/msgp
# github.com/toqueteos/trie v1.0.0
github.com/toqueteos/trie
# github.com/toqueteos/webbrowser v1.2.0
github.com/toqueteos/webbrowser
# github.com/tstranex/u2f v1.0.0
@@ -836,8 +834,6 @@ gopkg.in/ldap.v3
# gopkg.in/testfixtures.v2 v2.5.0
## explicit
gopkg.in/testfixtures.v2
# gopkg.in/toqueteos/substring.v1 v1.0.2
gopkg.in/toqueteos/substring.v1
# gopkg.in/warnings.v0 v0.1.2
gopkg.in/warnings.v0
# gopkg.in/yaml.v2 v2.2.8