aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_language_stats_nogogit.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-09-21 03:46:51 +0800
committerGitHub <noreply@github.com>2021-09-20 20:46:51 +0100
commitb231d0deabf8c5e5def785e65d4d62d9355fbcd4 (patch)
tree9f88080296bf87e2d639b6c24d4503e0ab045d75 /modules/git/repo_language_stats_nogogit.go
parent5ac857f4d43a8452089e22c820bd1f0ddb001b7a (diff)
downloadgitea-b231d0deabf8c5e5def785e65d4d62d9355fbcd4.tar.gz
gitea-b231d0deabf8c5e5def785e65d4d62d9355fbcd4.zip
Ignore Sync errors on pipes when doing `CheckAttributeReader.CheckPath`, fix the hang of `git cat-file` (#17096)
* Ignore Sync errors on pipes when doing `CheckAttributeReader.CheckPath` * apply env patch * Drop the Sync and fix a number of issues with the Close function Signed-off-by: Andrew Thornton <art27@cantab.net> * add logs for DBIndexer and CheckPath * Fix some more closing bugs Signed-off-by: Andrew Thornton <art27@cantab.net> * Add test case for language_stats Signed-off-by: Andrew Thornton <art27@cantab.net> * Update modules/indexer/stats/db.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/git/repo_language_stats_nogogit.go')
-rw-r--r--modules/git/repo_language_stats_nogogit.go47
1 files changed, 27 insertions, 20 deletions
diff --git a/modules/git/repo_language_stats_nogogit.go b/modules/git/repo_language_stats_nogogit.go
index c3b96ea841..8e9a3d6bcd 100644
--- a/modules/git/repo_language_stats_nogogit.go
+++ b/modules/git/repo_language_stats_nogogit.go
@@ -12,10 +12,12 @@ import (
"bytes"
"context"
"io"
+ "io/ioutil"
"math"
"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"
)
@@ -69,25 +71,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()
}
}
@@ -123,12 +132,11 @@ 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
}
sizes[language] += f.Size()
-
continue
}
}
@@ -186,7 +194,6 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
}
sizes[language] += f.Size()
-
continue
}