diff options
author | Jason Song <i@wolfogre.com> | 2023-01-09 11:50:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 11:50:54 +0800 |
commit | 7adc2de46404e32ed33f999d308ed56232cdfea5 (patch) | |
tree | 2404a22b5fa8a941eb5bfd16fd717fab29d899e4 /modules | |
parent | b878155b8741c2769b6aa50a80609c36822451c9 (diff) | |
download | gitea-7adc2de46404e32ed33f999d308ed56232cdfea5.tar.gz gitea-7adc2de46404e32ed33f999d308ed56232cdfea5.zip |
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>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/repo.go | 4 | ||||
-rw-r--r-- | modules/repository/repo.go | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index d15d28cab7..dba20b48a0 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -126,7 +126,7 @@ func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.Use userCanPush := true requireSigned := false if protectedBranch != nil { - userCanPush = protectedBranch.CanUserPush(doer.ID) + userCanPush = protectedBranch.CanUserPush(ctx, doer.ID) requireSigned = protectedBranch.RequireSignedCommits } @@ -831,7 +831,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string { if len(ref) == 0 { // maybe it's a renamed branch return getRefNameFromPath(ctx, path, func(s string) bool { - b, exist, err := git_model.FindRenamedBranch(ctx.Repo.Repository.ID, s) + b, exist, err := git_model.FindRenamedBranch(ctx, ctx.Repo.Repository.ID, s) if err != nil { log.Error("FindRenamedBranch", err) return false diff --git a/modules/repository/repo.go b/modules/repository/repo.go index a90eb8a764..d1a70e7c15 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -394,7 +394,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re defer content.Close() - _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repo.ID}) + _, err := git_model.NewLFSMetaObject(ctx, &git_model.LFSMetaObject{Pointer: p, RepositoryID: repo.ID}) if err != nil { log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, p, err) return err @@ -402,7 +402,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re if err := contentStore.Put(p, content); err != nil { log.Error("Repo[%-v]: Error storing content for LFS meta object %-v: %v", repo, p, err) - if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil { + if _, err2 := git_model.RemoveLFSMetaObjectByOid(ctx, repo.ID, p.Oid); err2 != nil { log.Error("Repo[%-v]: Error removing LFS meta object %-v: %v", repo, p, err2) } return err @@ -421,7 +421,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re var batch []lfs.Pointer for pointerBlob := range pointerChan { - meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid) + meta, err := git_model.GetLFSMetaObjectByOid(ctx, repo.ID, pointerBlob.Oid) if err != nil && err != git_model.ErrLFSObjectNotExist { log.Error("Repo[%-v]: Error querying LFS meta object %-v: %v", repo, pointerBlob.Pointer, err) return err @@ -441,7 +441,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re if exist { log.Trace("Repo[%-v]: LFS object %-v already present; creating meta object", repo, pointerBlob.Pointer) - _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID}) + _, err := git_model.NewLFSMetaObject(ctx, &git_model.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID}) if err != nil { log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, pointerBlob.Pointer, err) return err |