Skip to content

Fix deadlock when sqlite #5118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (repo *Repository) APIURL() string {

// APIFormat converts a Repository to api.Repository
func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
return repo.innerAPIFormat(mode, false)
return repo.innerAPIFormat(x, mode, false)
}

// GetCommitsCountCacheKey returns cache key used for commits count caching.
Expand All @@ -265,22 +265,22 @@ func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool)
return fmt.Sprintf("commits-count-%d-%s-%s", repo.ID, prefix, contextName)
}

func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository {
func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool) *api.Repository {
var parent *api.Repository

cloneLink := repo.CloneLink()
cloneLink := repo.cloneLink(e, false)
permission := &api.Permission{
Admin: mode >= AccessModeAdmin,
Push: mode >= AccessModeWrite,
Pull: mode >= AccessModeRead,
}
if !isParent {
err := repo.GetBaseRepo()
err := repo.getBaseRepo(e)
if err != nil {
log.Error(4, "APIFormat: %v", err)
}
if repo.BaseRepo != nil {
parent = repo.BaseRepo.innerAPIFormat(mode, true)
parent = repo.BaseRepo.innerAPIFormat(e, mode, true)
}
}
return &api.Repository{
Expand Down Expand Up @@ -617,11 +617,15 @@ func (repo *Repository) GetMirror() (err error) {
// returns an error on failure (NOTE: no error is returned for
// non-fork repositories, and BaseRepo will be left untouched)
func (repo *Repository) GetBaseRepo() (err error) {
return repo.getBaseRepo(x)
}

func (repo *Repository) getBaseRepo(e Engine) (err error) {
if !repo.IsFork {
return nil
}

repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
repo.BaseRepo, err = getRepositoryByID(e, repo.ForkID)
return err
}

Expand Down Expand Up @@ -889,7 +893,7 @@ func ComposeHTTPSCloneURL(owner, repo string) string {
return fmt.Sprintf("%s%s/%s.git", setting.AppURL, owner, repo)
}

func (repo *Repository) cloneLink(isUncyclo bool) *CloneLink {
func (repo *Repository) cloneLink(e Engine, isUncyclo bool) *CloneLink {
repoName := repo.Name
if isUncyclo {
repoName += ".wiki"
Expand All @@ -900,7 +904,7 @@ func (repo *Repository) cloneLink(isUncyclo bool) *CloneLink {
sshUser = setting.SSH.BuiltinServerUser
}

repo.Owner = repo.MustOwner()
repo.Owner = repo.mustOwner(e)
cl := new(CloneLink)
if setting.SSH.Port != 22 {
cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
Expand All @@ -915,7 +919,7 @@ func (repo *Repository) cloneLink(isUncyclo bool) *CloneLink {

// CloneLink returns clone URLs of repository.
func (repo *Repository) CloneLink() (cl *CloneLink) {
return repo.cloneLink(false)
return repo.cloneLink(x, false)
}

// MigrateRepoOptions contains the repository migrate options
Expand Down Expand Up @@ -1192,7 +1196,7 @@ func getRepoInitFile(tp, name string) ([]byte, error) {
}
}

func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
func prepareRepoCommit(e Engine, repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
// Clone to temporary path and do the init commit.
_, stderr, err := process.GetManager().Exec(
fmt.Sprintf("initRepository(git clone): %s", repoPath),
Expand All @@ -1208,7 +1212,7 @@ func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRep
return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
}

cloneLink := repo.CloneLink()
cloneLink := repo.cloneLink(e, false)
match := map[string]string{
"Name": repo.Name,
"Description": repo.Description,
Expand Down Expand Up @@ -1281,7 +1285,7 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C

defer os.RemoveAll(tmpDir)

if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
if err = prepareRepoCommit(e, repo, tmpDir, repoPath, opts); err != nil {
return fmt.Errorf("prepareRepoCommit: %v", err)
}

Expand Down Expand Up @@ -1386,7 +1390,7 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
return fmt.Errorf("addRepository: %v", err)
} else if err = prepareWebhooks(e, repo, HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: repo.APIFormat(AccessModeOwner),
Repository: repo.innerAPIFormat(e, AccessModeOwner, false),
Organization: u.APIFormat(),
Sender: doer.APIFormat(),
}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion models/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func UncycloFilenameToName(filename string) (string, error) {

// UncycloCloneLink returns clone URLs of repository wiki.
func (repo *Repository) UncycloCloneLink() *CloneLink {
return repo.cloneLink(true)
return repo.cloneLink(x, true)
}

// UncycloPath returns wiki data path by given user and repository name.
Expand Down