mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 10:56:10 +01:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -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 | ||||
| 					} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user