1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Move some helper files out of models (#19355)

* Move some helper files out of models

* Some improvements

Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
Lunny Xiao
2022-05-09 00:46:32 +08:00
committed by GitHub
parent d4834071da
commit 4ca1d7547a
23 changed files with 108 additions and 107 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)
}
}()