mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Use context parameter in models/git (#22367)
After #22362, we can feel free to use transactions without `db.DefaultContext`. And there are still lots of models using `db.DefaultContext`, I think we should refactor them carefully and one by one. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -11,6 +11,7 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	git_model "code.gitea.io/gitea/models/git"
 | 
			
		||||
	issues_model "code.gitea.io/gitea/models/issues"
 | 
			
		||||
	"code.gitea.io/gitea/modules/git/pipeline"
 | 
			
		||||
@@ -115,7 +116,7 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Then we need to check that this pointer is in the db
 | 
			
		||||
		if _, err := git_model.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil {
 | 
			
		||||
		if _, err := git_model.GetLFSMetaObjectByOid(db.DefaultContext, pr.HeadRepo.ID, pointer.Oid); err != nil {
 | 
			
		||||
			if err == git_model.ErrLFSObjectNotExist {
 | 
			
		||||
				log.Warn("During merge of: %d in %-v, there is a pointer to LFS Oid: %s which although present in the LFS store is not associated with the head repo %-v", pr.Index, pr.BaseRepo, pointer.Oid, pr.HeadRepo)
 | 
			
		||||
				continue
 | 
			
		||||
@@ -128,7 +129,7 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg
 | 
			
		||||
		// Therefore it should be associated with the base repo
 | 
			
		||||
		meta := &git_model.LFSMetaObject{Pointer: pointer}
 | 
			
		||||
		meta.RepositoryID = pr.BaseRepoID
 | 
			
		||||
		if _, err := git_model.NewLFSMetaObject(meta); err != nil {
 | 
			
		||||
		if _, err := git_model.NewLFSMetaObject(db.DefaultContext, meta); err != nil {
 | 
			
		||||
			_ = catFileBatchReader.CloseWithError(err)
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user