diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /services/repository | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'services/repository')
-rw-r--r-- | services/repository/adopt.go | 4 | ||||
-rw-r--r-- | services/repository/avatar.go | 6 | ||||
-rw-r--r-- | services/repository/files/patch.go | 2 | ||||
-rw-r--r-- | services/repository/files/update.go | 2 | ||||
-rw-r--r-- | services/repository/push.go | 4 |
5 files changed, 9 insertions, 9 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go index b287d94f9d..1e8c22a479 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -208,7 +208,7 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error } } - if exist, err := repo_model.IsRepositoryExist(u, repoName); err != nil { + if exist, err := repo_model.IsRepositoryExist(db.DefaultContext, u, repoName); err != nil { return err } else if exist { return repo_model.ErrRepoAlreadyExist{ @@ -238,7 +238,7 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad if len(repoNamesToCheck) == 0 { return nil } - ctxUser, err := user_model.GetUserByName(userName) + ctxUser, err := user_model.GetUserByName(db.DefaultContext, userName) if err != nil { if user_model.IsErrUserNotExist(err) { log.Debug("Missing user: %s", userName) diff --git a/services/repository/avatar.go b/services/repository/avatar.go index f51a312e17..dcf04c7e54 100644 --- a/services/repository/avatar.go +++ b/services/repository/avatar.go @@ -44,7 +44,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error { // Users can upload the same image to other repo - prefix it with ID // Then repo will be removed - only it avatar file will be removed repo.Avatar = newAvatar - if err := repo_model.UpdateRepositoryColsCtx(ctx, repo, "avatar"); err != nil { + if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil { return fmt.Errorf("UploadAvatar: Update repository avatar: %v", err) } @@ -83,7 +83,7 @@ func DeleteAvatar(repo *repo_model.Repository) error { defer committer.Close() repo.Avatar = "" - if err := repo_model.UpdateRepositoryColsCtx(ctx, repo, "avatar"); err != nil { + if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil { return fmt.Errorf("DeleteAvatar: Update repository avatar: %v", err) } @@ -117,5 +117,5 @@ func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model. return err } - return repo_model.UpdateRepositoryColsCtx(ctx, generateRepo, "avatar") + return repo_model.UpdateRepositoryCols(ctx, generateRepo, "avatar") } diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go index 240cb4fe2c..73464f31f3 100644 --- a/services/repository/files/patch.go +++ b/services/repository/files/patch.go @@ -66,7 +66,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode return err } } else { - protectedBranch, err := models.GetProtectedBranchBy(repo.ID, opts.OldBranch) + protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch) if err != nil { return err } diff --git a/services/repository/files/update.go b/services/repository/files/update.go index 2cb40aac47..a093ee5da7 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -462,7 +462,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch func VerifyBranchProtection(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, branchName, treePath string) error { - protectedBranch, err := models.GetProtectedBranchBy(repo.ID, branchName) + protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName) if err != nil { return err } diff --git a/services/repository/push.go b/services/repository/push.go index 4eb52c18c2..5ca8c73983 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -181,7 +181,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } } // Update the is empty and default_branch columns - if err := repo_model.UpdateRepositoryCols(repo, "default_branch", "is_empty"); err != nil { + if err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "default_branch", "is_empty"); err != nil { return fmt.Errorf("UpdateRepositoryCols: %v", err) } } @@ -269,7 +269,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } // Even if user delete a branch on a repository which he didn't watch, he will be watch that. - if err = repo_model.WatchIfAuto(opts.PusherID, repo.ID, true); err != nil { + if err = repo_model.WatchIfAuto(db.DefaultContext, opts.PusherID, repo.ID, true); err != nil { log.Warn("Fail to perform auto watch on user %v for repo %v: %v", opts.PusherID, repo.ID, err) } } else { |