From 4ca1d7547a2c32cc65ca23d1a7698d1a8c921d65 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 9 May 2022 00:46:32 +0800 Subject: Move some helper files out of models (#19355) * Move some helper files out of models * Some improvements Co-authored-by: delvh --- routers/init.go | 7 +++++-- routers/web/repo/branch.go | 2 +- routers/web/repo/http.go | 19 ++++++++++--------- routers/web/repo/lfs.go | 5 +++-- 4 files changed, 19 insertions(+), 14 deletions(-) (limited to 'routers') diff --git a/routers/init.go b/routers/init.go index 2e7fec86db..759945ce25 100644 --- a/routers/init.go +++ b/routers/init.go @@ -73,7 +73,7 @@ func mustInitCtx(ctx context.Context, fn func(ctx context.Context) error) { func InitGitServices() { setting.NewServices() mustInit(storage.Init) - mustInit(repo_service.NewContext) + mustInit(repo_service.Init) } func syncAppPathForGit(ctx context.Context) error { @@ -116,7 +116,9 @@ func GlobalInitInstalled(ctx context.Context) { // Setup i18n translation.InitLocales() - InitGitServices() + setting.NewServices() + mustInit(storage.Init) + mailer.NewContext() mustInit(cache.NewContext) notification.NewContext() @@ -138,6 +140,7 @@ func GlobalInitInstalled(ctx context.Context) { mustInit(oauth2.Init) models.NewRepoContext() + mustInit(repo_service.Init) // Booting long running goroutines. cron.NewContext(ctx) diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 732b9c9d54..08f388bf3c 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -129,7 +129,7 @@ func RestoreBranchPost(ctx *context.Context) { if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{ Remote: ctx.Repo.Repository.RepoPath(), Branch: fmt.Sprintf("%s:%s%s", deletedBranch.Commit, git.BranchPrefix, deletedBranch.Name), - Env: models.PushingEnvironment(ctx.Doer, ctx.Repo.Repository), + Env: repo_module.PushingEnvironment(ctx.Doer, ctx.Repo.Repository), }); err != nil { if strings.Contains(err.Error(), "already exists") { log.Debug("RestoreBranch: Can't restore branch '%s', since one with same name already exist", deletedBranch.Name) diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index cc44c8e7e4..a52d9b76c2 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -27,6 +27,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" @@ -204,21 +205,21 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { } environ = []string{ - models.EnvRepoUsername + "=" + username, - models.EnvRepoName + "=" + reponame, - models.EnvPusherName + "=" + ctx.Doer.Name, - models.EnvPusherID + fmt.Sprintf("=%d", ctx.Doer.ID), - models.EnvAppURL + "=" + setting.AppURL, + repo_module.EnvRepoUsername + "=" + username, + repo_module.EnvRepoName + "=" + reponame, + repo_module.EnvPusherName + "=" + ctx.Doer.Name, + repo_module.EnvPusherID + fmt.Sprintf("=%d", ctx.Doer.ID), + repo_module.EnvAppURL + "=" + setting.AppURL, } if !ctx.Doer.KeepEmailPrivate { - environ = append(environ, models.EnvPusherEmail+"="+ctx.Doer.Email) + environ = append(environ, repo_module.EnvPusherEmail+"="+ctx.Doer.Email) } if isWiki { - environ = append(environ, models.EnvRepoIsWiki+"=true") + environ = append(environ, repo_module.EnvRepoIsWiki+"=true") } else { - environ = append(environ, models.EnvRepoIsWiki+"=false") + environ = append(environ, repo_module.EnvRepoIsWiki+"=false") } } @@ -269,7 +270,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { } } - environ = append(environ, models.EnvRepoID+fmt.Sprintf("=%d", repo.ID)) + environ = append(environ, repo_module.EnvRepoID+fmt.Sprintf("=%d", repo.ID)) w := ctx.Resp r := ctx.Req diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index e0ef864edf..7c2ff1cfae 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -23,6 +23,7 @@ import ( "code.gitea.io/gitea/modules/git/pipeline" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/typesniffer" @@ -103,14 +104,14 @@ func LFSLocks(ctx *context.Context) { } // Clone base repo. - tmpBasePath, err := models.CreateTemporaryPath("locks") + tmpBasePath, err := repo_module.CreateTemporaryPath("locks") if err != nil { log.Error("Failed to create temporary path: %v", err) ctx.ServerError("LFSLocks", err) return } defer func() { - if err := models.RemoveTemporaryPath(tmpBasePath); err != nil { + if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil { log.Error("LFSLocks: RemoveTemporaryPath: %v", err) } }() -- cgit v1.2.3