mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00: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:
@@ -106,7 +106,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// If no query params path or id
|
||||
lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit)
|
||||
lockList, err := git_model.GetLFSLockByRepoID(ctx, repository.ID, cursor, limit)
|
||||
if err != nil {
|
||||
log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
@@ -167,7 +167,7 @@ func PostLockHandler(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
lock, err := git_model.CreateLFSLock(repository, &git_model.LFSLock{
|
||||
lock, err := git_model.CreateLFSLock(ctx, repository, &git_model.LFSLock{
|
||||
Path: req.Path,
|
||||
OwnerID: ctx.Doer.ID,
|
||||
})
|
||||
@@ -233,7 +233,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
||||
} else if limit < 0 {
|
||||
limit = 0
|
||||
}
|
||||
lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit)
|
||||
lockList, err := git_model.GetLFSLockByRepoID(ctx, repository.ID, cursor, limit)
|
||||
if err != nil {
|
||||
log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err)
|
||||
ctx.JSON(http.StatusInternalServerError, api.LFSLockError{
|
||||
@@ -300,7 +300,7 @@ func UnLockHandler(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
lock, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force)
|
||||
lock, err := git_model.DeleteLFSLockByID(ctx, ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force)
|
||||
if err != nil {
|
||||
if git_model.IsErrLFSUnauthorizedAction(err) {
|
||||
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
|
||||
|
@@ -197,7 +197,7 @@ func BatchHandler(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid)
|
||||
meta, err := git_model.GetLFSMetaObjectByOid(ctx, repository.ID, p.Oid)
|
||||
if err != nil && err != git_model.ErrLFSObjectNotExist {
|
||||
log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
@@ -223,14 +223,14 @@ func BatchHandler(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if exists && meta == nil {
|
||||
accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid)
|
||||
accessible, err := git_model.LFSObjectAccessible(ctx, ctx.Doer, p.Oid)
|
||||
if err != nil {
|
||||
log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if accessible {
|
||||
_, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
|
||||
_, err := git_model.NewLFSMetaObject(ctx, &git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
|
||||
if err != nil {
|
||||
log.Error("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err)
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
@@ -297,7 +297,7 @@ func UploadHandler(ctx *context.Context) {
|
||||
|
||||
uploadOrVerify := func() error {
|
||||
if exists {
|
||||
accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid)
|
||||
accessible, err := git_model.LFSObjectAccessible(ctx, ctx.Doer, p.Oid)
|
||||
if err != nil {
|
||||
log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err)
|
||||
return err
|
||||
@@ -323,7 +323,7 @@ func UploadHandler(ctx *context.Context) {
|
||||
log.Error("Error putting LFS MetaObject [%s] into content store. Error: %v", p.Oid, err)
|
||||
return err
|
||||
}
|
||||
_, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
|
||||
_, err := git_model.NewLFSMetaObject(ctx, &git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ func UploadHandler(ctx *context.Context) {
|
||||
} else {
|
||||
writeStatus(ctx, http.StatusInternalServerError)
|
||||
}
|
||||
if _, err = git_model.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil {
|
||||
if _, err = git_model.RemoveLFSMetaObjectByOid(ctx, repository.ID, p.Oid); err != nil {
|
||||
log.Error("Error whilst removing metaobject for LFS OID[%s]: %v", p.Oid, err)
|
||||
}
|
||||
return
|
||||
@@ -398,7 +398,7 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module
|
||||
return nil
|
||||
}
|
||||
|
||||
meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid)
|
||||
meta, err := git_model.GetLFSMetaObjectByOid(ctx, repository.ID, p.Oid)
|
||||
if err != nil {
|
||||
log.Error("Unable to get LFS OID[%s] Error: %v", p.Oid, err)
|
||||
writeStatus(ctx, http.StatusNotFound)
|
||||
|
Reference in New Issue
Block a user