You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

transfer.go 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repository
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/notification"
  8. "code.gitea.io/gitea/modules/sync"
  9. "github.com/unknwon/com"
  10. )
  11. // repoWorkingPool represents a working pool to order the parallel changes to the same repository
  12. var repoWorkingPool = sync.NewExclusivePool()
  13. // TransferOwnership transfers all corresponding setting from old user to new one.
  14. func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error {
  15. if err := repo.GetOwner(); err != nil {
  16. return err
  17. }
  18. oldOwner := repo.Owner
  19. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  20. if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil {
  21. repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  22. return err
  23. }
  24. repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  25. notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
  26. return nil
  27. }
  28. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  29. func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
  30. oldRepoName := repo.Name
  31. // Change repository directory name. We must lock the local copy of the
  32. // repo so that we can atomically rename the repo path and updates the
  33. // local copy's origin accordingly.
  34. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  35. if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
  36. repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  37. return err
  38. }
  39. repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  40. notification.NotifyRenameRepository(doer, repo, oldRepoName)
  41. return nil
  42. }