diff options
Diffstat (limited to 'modules/git/repo_language_stats_gogit.go')
-rw-r--r-- | modules/git/repo_language_stats_gogit.go | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/modules/git/repo_language_stats_gogit.go b/modules/git/repo_language_stats_gogit.go index 3abce1f077..1f2738a5a8 100644 --- a/modules/git/repo_language_stats_gogit.go +++ b/modules/git/repo_language_stats_gogit.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/analyze" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/util" "github.com/go-enry/go-enry/v2" "github.com/go-git/go-git/v5" @@ -50,25 +51,32 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err indexFilename, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID) if err == nil { defer deleteTemporaryFile() - - checker = &CheckAttributeReader{ - Attributes: []string{"linguist-vendored", "linguist-generated", "linguist-language"}, - Repo: repo, - IndexFile: indexFilename, - } - ctx, cancel := context.WithCancel(DefaultContext) - if err := checker.Init(ctx); err != nil { - log.Error("Unable to open checker for %s. Error: %v", commitID, err) - } else { - go func() { - err = checker.Run() - if err != nil { - log.Error("Unable to open checker for %s. Error: %v", commitID, err) - cancel() - } + tmpWorkTree, err := ioutil.TempDir("", "empty-work-dir") + if err == nil { + defer func() { + _ = util.RemoveAll(tmpWorkTree) }() + + checker = &CheckAttributeReader{ + Attributes: []string{"linguist-vendored", "linguist-generated", "linguist-language"}, + Repo: repo, + IndexFile: indexFilename, + WorkTree: tmpWorkTree, + } + ctx, cancel := context.WithCancel(DefaultContext) + if err := checker.Init(ctx); err != nil { + log.Error("Unable to open checker for %s. Error: %v", commitID, err) + } else { + go func() { + err = checker.Run() + if err != nil { + log.Error("Unable to open checker for %s. Error: %v", commitID, err) + cancel() + } + }() + } + defer cancel() } - defer cancel() } } @@ -99,7 +107,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err if language, has := attrs["linguist-language"]; has && language != "unspecified" && language != "" { // group languages, such as Pug -> HTML; SCSS -> CSS group := enry.GetLanguageGroup(language) - if len(group) == 0 { + if len(group) != 0 { language = group } |