|
|
@ -7,10 +7,14 @@ package repository |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/notification" |
|
|
|
"code.gitea.io/gitea/modules/notification" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/sync" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/unknwon/com" |
|
|
|
"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.
|
|
|
|
// TransferOwnership transfers all corresponding setting from old user to new one.
|
|
|
|
func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error { |
|
|
|
func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error { |
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
@ -19,12 +23,12 @@ func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repo |
|
|
|
|
|
|
|
|
|
|
|
oldOwner := repo.Owner |
|
|
|
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 { |
|
|
|
if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil { |
|
|
|
models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
repoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
repoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
|
|
|
|
|
|
|
|
notification.NotifyTransferRepository(doer, repo, oldOwner.Name) |
|
|
|
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
|
|
|
|
// repo so that we can atomically rename the repo path and updates the
|
|
|
|
// local copy's origin accordingly.
|
|
|
|
// 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 { |
|
|
|
if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil { |
|
|
|
models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
repoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
models.RepoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
repoWorkingPool.CheckOut(com.ToStr(repo.ID)) |
|
|
|
|
|
|
|
|
|
|
|
notification.NotifyRenameRepository(doer, repo, oldRepoName) |
|
|
|
notification.NotifyRenameRepository(doer, repo, oldRepoName) |
|
|
|
|
|
|
|
|
|
|
|