diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-05-04 13:42:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-04 13:42:02 +0800 |
commit | 1773e88643a2df7e7efbe86ec424409b45a4d576 (patch) | |
tree | 66776994b960b1277264fd4e7d74ce3380701488 /models/update.go | |
parent | 59f5bbab0d6c1aa00fd58140860093331ab0140f (diff) | |
download | gitea-1773e88643a2df7e7efbe86ec424409b45a4d576.tar.gz gitea-1773e88643a2df7e7efbe86ec424409b45a4d576.zip |
Drop db operations from hook commands (#1514)
* move all database operations from hook command to web command and instead of internal routes
* bug fixed
* adjust the import path sequences
* remove unused return value on hookSetup
Diffstat (limited to 'models/update.go')
-rw-r--r-- | models/update.go | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/models/update.go b/models/update.go index b3a8a1c9fb..7ee00f2c27 100644 --- a/models/update.go +++ b/models/update.go @@ -65,11 +65,11 @@ type PushUpdateOptions struct { // PushUpdate must be called for any push actions in order to // generates necessary push action history feeds. -func PushUpdate(opts PushUpdateOptions) (err error) { +func PushUpdate(opts PushUpdateOptions) (repo *Repository, err error) { isNewRef := opts.OldCommitID == git.EmptySHA isDelRef := opts.NewCommitID == git.EmptySHA if isNewRef && isDelRef { - return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA) + return nil, fmt.Errorf("Old and new revisions are both %s", git.EmptySHA) } repoPath := RepoPath(opts.RepoUserName, opts.RepoName) @@ -77,28 +77,28 @@ func PushUpdate(opts PushUpdateOptions) (err error) { gitUpdate := exec.Command("git", "update-server-info") gitUpdate.Dir = repoPath if err = gitUpdate.Run(); err != nil { - return fmt.Errorf("Failed to call 'git update-server-info': %v", err) + return nil, fmt.Errorf("Failed to call 'git update-server-info': %v", err) } - if isDelRef { - log.GitLogger.Info("Reference '%s' has been deleted from '%s/%s' by %s", - opts.RefFullName, opts.RepoUserName, opts.RepoName, opts.PusherName) - return nil + owner, err := GetUserByName(opts.RepoUserName) + if err != nil { + return nil, fmt.Errorf("GetUserByName: %v", err) } - gitRepo, err := git.OpenRepository(repoPath) + repo, err = GetRepositoryByName(owner.ID, opts.RepoName) if err != nil { - return fmt.Errorf("OpenRepository: %v", err) + return nil, fmt.Errorf("GetRepositoryByName: %v", err) } - owner, err := GetUserByName(opts.RepoUserName) - if err != nil { - return fmt.Errorf("GetUserByName: %v", err) + if isDelRef { + log.GitLogger.Info("Reference '%s' has been deleted from '%s/%s' by %s", + opts.RefFullName, opts.RepoUserName, opts.RepoName, opts.PusherName) + return repo, nil } - repo, err := GetRepositoryByName(owner.ID, opts.RepoName) + gitRepo, err := git.OpenRepository(repoPath) if err != nil { - return fmt.Errorf("GetRepositoryByName: %v", err) + return nil, fmt.Errorf("OpenRepository: %v", err) } if err = repo.UpdateSize(); err != nil { @@ -116,14 +116,14 @@ func PushUpdate(opts PushUpdateOptions) (err error) { NewCommitID: opts.NewCommitID, Commits: &PushCommits{}, }); err != nil { - return fmt.Errorf("CommitRepoAction (tag): %v", err) + return nil, fmt.Errorf("CommitRepoAction (tag): %v", err) } - return nil + return repo, nil } newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { - return fmt.Errorf("gitRepo.GetCommit: %v", err) + return nil, fmt.Errorf("gitRepo.GetCommit: %v", err) } // Push new branch. @@ -131,12 +131,12 @@ func PushUpdate(opts PushUpdateOptions) (err error) { if isNewRef { l, err = newCommit.CommitsBeforeLimit(10) if err != nil { - return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err) + return nil, fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err) } } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { - return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err) + return nil, fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err) } } @@ -149,7 +149,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) { NewCommitID: opts.NewCommitID, Commits: ListToPushCommits(l), }); err != nil { - return fmt.Errorf("CommitRepoAction (branch): %v", err) + return nil, fmt.Errorf("CommitRepoAction (branch): %v", err) } - return nil + return repo, nil } |