summaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-12-06 12:00:50 +0800
committerGitHub <noreply@github.com>2019-12-06 12:00:50 +0800
commit77730db25768036a12e16cef9839b9492218303f (patch)
treebc1df7483f0be61609fa668093f2d04011faa100 /services/repository
parent9ff5b7555913964ebc6c463b00055394c85b8689 (diff)
downloadgitea-77730db25768036a12e16cef9839b9492218303f.tar.gz
gitea-77730db25768036a12e16cef9839b9492218303f.zip
Move repoWorkPool outside rename/transfer repository (#9086)
* Move repoWorkPool outside rename/transfer repository * fix import * Fix test
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/transfer.go26
1 files changed, 12 insertions, 14 deletions
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index 2d20dcd1a2..9b3c084eab 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.go
@@ -5,10 +5,10 @@
package repository
import (
- "fmt"
-
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/notification"
+
+ "github.com/unknwon/com"
)
// TransferOwnership transfers all corresponding setting from old user to new one.
@@ -19,13 +19,12 @@ func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repo
oldOwner := repo.Owner
+ models.RepoWorkingPool.CheckIn(com.ToStr(repo.ID))
if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil {
+ models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID))
return err
}
-
- if err := models.NewRepoRedirect(oldOwner.ID, repo.ID, repo.Name, repo.Name); err != nil {
- return fmt.Errorf("NewRepoRedirect: %v", err)
- }
+ models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID))
notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
@@ -36,17 +35,16 @@ func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repo
func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
oldRepoName := repo.Name
- if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
- return err
- }
-
- if err := repo.GetOwner(); err != nil {
- return err
- }
+ // Change repository directory name. We must lock the local copy of the
+ // repo so that we can atomically rename the repo path and updates the
+ // local copy's origin accordingly.
- if err := models.NewRepoRedirect(repo.Owner.ID, repo.ID, oldRepoName, newRepoName); err != nil {
+ models.RepoWorkingPool.CheckIn(com.ToStr(repo.ID))
+ if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
+ models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID))
return err
}
+ models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID))
notification.NotifyRenameRepository(doer, repo, oldRepoName)