From d32eac44b16c7b3320b586f402621de84fafa185 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 15 Jan 2020 11:14:50 +0800 Subject: [PATCH] Move RepoWorkingPool to services/repository package (#9754) * Move RepoWorkingPool to services/repository package * Make repoWorkingPool private Co-authored-by: Antoine GIRARD --- models/repo.go | 4 ---- services/repository/transfer.go | 16 ++++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/models/repo.go b/models/repo.go index ee9e6a504ba..2c9dafefc92 100644 --- a/models/repo.go +++ b/models/repo.go @@ -33,7 +33,6 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/sync" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" @@ -41,9 +40,6 @@ import ( "xorm.io/builder" ) -// RepoWorkingPool represents a working pool to order the parallel changes to the same repository -var RepoWorkingPool = sync.NewExclusivePool() - var ( // ErrMirrorNotExist mirror does not exist error ErrMirrorNotExist = errors.New("Mirror does not exist") diff --git a/services/repository/transfer.go b/services/repository/transfer.go index 9b3c084eab5..978a966c415 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -7,10 +7,14 @@ package repository import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/modules/sync" "github.com/unknwon/com" ) +// repoWorkingPool represents a working pool to order the parallel changes to the same repository +var repoWorkingPool = sync.NewExclusivePool() + // TransferOwnership transfers all corresponding setting from old user to new one. func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error { if err := repo.GetOwner(); err != nil { @@ -19,12 +23,12 @@ func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repo oldOwner := repo.Owner - models.RepoWorkingPool.CheckIn(com.ToStr(repo.ID)) + repoWorkingPool.CheckIn(com.ToStr(repo.ID)) if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil { - models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) + repoWorkingPool.CheckOut(com.ToStr(repo.ID)) return err } - models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) + repoWorkingPool.CheckOut(com.ToStr(repo.ID)) notification.NotifyTransferRepository(doer, repo, oldOwner.Name) @@ -39,12 +43,12 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam // repo so that we can atomically rename the repo path and updates the // local copy's origin accordingly. - models.RepoWorkingPool.CheckIn(com.ToStr(repo.ID)) + repoWorkingPool.CheckIn(com.ToStr(repo.ID)) if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil { - models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) + repoWorkingPool.CheckOut(com.ToStr(repo.ID)) return err } - models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) + repoWorkingPool.CheckOut(com.ToStr(repo.ID)) notification.NotifyRenameRepository(doer, repo, oldRepoName)