diff options
Diffstat (limited to 'modules/repository')
-rw-r--r-- | modules/repository/adopt.go | 3 | ||||
-rw-r--r-- | modules/repository/check.go | 8 | ||||
-rw-r--r-- | modules/repository/create.go | 3 | ||||
-rw-r--r-- | modules/repository/fork.go | 7 | ||||
-rw-r--r-- | modules/repository/generate.go | 8 | ||||
-rw-r--r-- | modules/repository/hooks.go | 2 | ||||
-rw-r--r-- | modules/repository/init.go | 8 | ||||
-rw-r--r-- | modules/repository/repo.go | 2 | ||||
-rw-r--r-- | modules/repository/update.go | 5 |
9 files changed, 25 insertions, 21 deletions
diff --git a/modules/repository/adopt.go b/modules/repository/adopt.go index 9371822fbc..daefee9c74 100644 --- a/modules/repository/adopt.go +++ b/modules/repository/adopt.go @@ -5,6 +5,7 @@ package repository import ( + "context" "fmt" "os" "path/filepath" @@ -47,7 +48,7 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode IsEmpty: !opts.AutoInit, } - if err := db.WithTx(func(ctx *db.Context) error { + if err := db.WithTx(func(ctx context.Context) error { repoPath := models.RepoPath(u.Name, repo.Name) isExist, err := util.IsExist(repoPath) if err != nil { diff --git a/modules/repository/check.go b/modules/repository/check.go index 1b550ad4f0..78e6f8a901 100644 --- a/modules/repository/check.go +++ b/modules/repository/check.go @@ -24,7 +24,7 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []string) error { log.Trace("Doing: GitFsck") if err := db.Iterate( - db.DefaultContext(), + db.DefaultContext, new(models.Repository), builder.Expr("id>0 AND is_fsck_enabled=?", true), func(idx int, bean interface{}) error { @@ -59,7 +59,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro args = append([]string{"gc"}, args...) if err := db.Iterate( - db.DefaultContext(), + db.DefaultContext, new(models.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { @@ -94,7 +94,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro } // Now update the size of the repository - if err := repo.UpdateSize(db.DefaultContext()); err != nil { + if err := repo.UpdateSize(db.DefaultContext); err != nil { log.Error("Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err) desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err) if err = models.CreateRepositoryNotice(desc); err != nil { @@ -116,7 +116,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error) { repos := make([]*models.Repository, 0, 10) if err := db.Iterate( - db.DefaultContext(), + db.DefaultContext, new(models.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { diff --git a/modules/repository/create.go b/modules/repository/create.go index 80f446e83f..0e91a73b83 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -5,6 +5,7 @@ package repository import ( + "context" "fmt" "strings" @@ -55,7 +56,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod var rollbackRepo *models.Repository - if err := db.WithTx(func(ctx *db.Context) error { + if err := db.WithTx(func(ctx context.Context) error { if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil { return err } diff --git a/modules/repository/fork.go b/modules/repository/fork.go index ff69f75b32..59c07271a6 100644 --- a/modules/repository/fork.go +++ b/modules/repository/fork.go @@ -5,6 +5,7 @@ package repository import ( + "context" "fmt" "strings" "time" @@ -79,7 +80,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m panic(panicErr) }() - err = db.WithTx(func(ctx *db.Context) error { + err = db.WithTx(func(ctx context.Context) error { if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil { return err } @@ -123,7 +124,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m } // even if below operations failed, it could be ignored. And they will be retried - ctx := db.DefaultContext() + ctx := db.DefaultContext if err := repo.UpdateSize(ctx); err != nil { log.Error("Failed to update size for repository: %v", err) } @@ -136,7 +137,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m // ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo func ConvertForkToNormalRepository(repo *models.Repository) error { - err := db.WithTx(func(ctx *db.Context) error { + err := db.WithTx(func(ctx context.Context) error { repo, err := models.GetRepositoryByIDCtx(ctx, repo.ID) if err != nil { return err diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 8ab518add5..4fcebc06dc 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -5,6 +5,7 @@ package repository import ( + "context" "fmt" "os" "path" @@ -13,7 +14,6 @@ import ( "time" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" @@ -185,7 +185,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch) } -func generateGitContent(ctx *db.Context, repo, templateRepo, generateRepo *models.Repository) (err error) { +func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *models.Repository) (err error) { tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name) if err != nil { return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err) @@ -223,7 +223,7 @@ func generateGitContent(ctx *db.Context, repo, templateRepo, generateRepo *model } // GenerateGitContent generates git content from a template repository -func GenerateGitContent(ctx *db.Context, templateRepo, generateRepo *models.Repository) error { +func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.Repository) error { if err := generateGitContent(ctx, generateRepo, templateRepo, generateRepo); err != nil { return err } @@ -239,7 +239,7 @@ func GenerateGitContent(ctx *db.Context, templateRepo, generateRepo *models.Repo } // GenerateRepository generates a repository from a template -func GenerateRepository(ctx *db.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { +func GenerateRepository(ctx context.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { generateRepo := &models.Repository{ OwnerID: owner.ID, Owner: owner, diff --git a/modules/repository/hooks.go b/modules/repository/hooks.go index e219903f75..6072dda016 100644 --- a/modules/repository/hooks.go +++ b/modules/repository/hooks.go @@ -221,7 +221,7 @@ func SyncRepositoryHooks(ctx context.Context) error { log.Trace("Doing: SyncRepositoryHooks") if err := db.Iterate( - db.DefaultContext(), + db.DefaultContext, new(models.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { diff --git a/modules/repository/init.go b/modules/repository/init.go index 2a86e964ca..5a1ff7e98b 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -6,6 +6,7 @@ package repository import ( "bytes" + "context" "fmt" "os" "path/filepath" @@ -13,7 +14,6 @@ import ( "time" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -22,7 +22,7 @@ import ( "github.com/unknwon/com" ) -func prepareRepoCommit(ctx *db.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error { +func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error { commitTimeStr := time.Now().Format(time.RFC3339) authorSig := repo.Owner.NewGitSig() @@ -196,7 +196,7 @@ func checkInitRepository(owner, name string) (err error) { return nil } -func adoptRepository(ctx *db.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) @@ -283,7 +283,7 @@ func adoptRepository(ctx *db.Context, repoPath string, u *models.User, repo *mod } // InitRepository initializes README and .gitignore if needed. -func initRepository(ctx *db.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil { return err } diff --git a/modules/repository/repo.go b/modules/repository/repo.go index b59a80ee2f..ee970fd711 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -133,7 +133,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models. } } - if err = repo.UpdateSize(db.DefaultContext()); err != nil { + if err = repo.UpdateSize(db.DefaultContext); err != nil { log.Error("Failed to update size for repository: %v", err) } diff --git a/modules/repository/update.go b/modules/repository/update.go index d9ff12e1ad..b9a5db2a6a 100644 --- a/modules/repository/update.go +++ b/modules/repository/update.go @@ -5,6 +5,7 @@ package repository import ( + "context" "fmt" "strings" "time" @@ -17,7 +18,7 @@ import ( // PushUpdateAddDeleteTags updates a number of added and delete tags func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, addTags, delTags []string) error { - return db.WithTx(func(ctx *db.Context) error { + return db.WithTx(func(ctx context.Context) error { if err := models.PushUpdateDeleteTagsContext(ctx, repo, delTags); err != nil { return err } @@ -26,7 +27,7 @@ func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, a } // pushUpdateAddTags updates a number of add tags -func pushUpdateAddTags(ctx *db.Context, repo *models.Repository, gitRepo *git.Repository, tags []string) error { +func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *git.Repository, tags []string) error { if len(tags) == 0 { return nil } |