summaryrefslogtreecommitdiffstats
path: root/services/pull/update.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-19 23:26:57 +0000
committerGitHub <noreply@github.com>2022-01-19 23:26:57 +0000
commit5cb0c9aa0d7eed087055b1efca79628957207d36 (patch)
treed117a514e1f17e5f6bfcda1be273f6a971112663 /services/pull/update.go
parent4563148a61ba892e8f2bb66342f00a950bcd5315 (diff)
downloadgitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz
gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/pull/update.go')
-rw-r--r--services/pull/update.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/services/pull/update.go b/services/pull/update.go
index 8ca7e4cee7..09cf1ce52e 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -5,6 +5,7 @@
package pull
import (
+ "context"
"fmt"
"code.gitea.io/gitea/models"
@@ -15,7 +16,7 @@ import (
)
// Update updates pull request with base branch.
-func Update(pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error {
+func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error {
var (
pr *models.PullRequest
style repo_model.MergeStyle
@@ -48,14 +49,14 @@ func Update(pull *models.PullRequest, doer *user_model.User, message string, reb
return fmt.Errorf("LoadBaseRepo: %v", err)
}
- diffCount, err := GetDiverging(pull)
+ diffCount, err := GetDiverging(ctx, pull)
if err != nil {
return err
} else if diffCount.Behind == 0 {
return fmt.Errorf("HeadBranch of PR %d is up to date", pull.Index)
}
- _, err = rawMerge(pr, doer, style, "", message)
+ _, err = rawMerge(ctx, pr, doer, style, "", message)
defer func() {
if rebase {
@@ -113,7 +114,7 @@ func IsUserAllowedToUpdate(pull *models.PullRequest, user *user_model.User) (mer
}
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
-func GetDiverging(pr *models.PullRequest) (*git.DivergeObject, error) {
+func GetDiverging(ctx context.Context, pr *models.PullRequest) (*git.DivergeObject, error) {
log.Trace("GetDiverging[%d]: compare commits", pr.ID)
if err := pr.LoadBaseRepo(); err != nil {
return nil, err
@@ -122,7 +123,7 @@ func GetDiverging(pr *models.PullRequest) (*git.DivergeObject, error) {
return nil, err
}
- tmpRepo, err := createTemporaryRepo(pr)
+ tmpRepo, err := createTemporaryRepo(ctx, pr)
if err != nil {
if !models.IsErrBranchDoesNotExist(err) {
log.Error("CreateTemporaryRepo: %v", err)
@@ -135,6 +136,6 @@ func GetDiverging(pr *models.PullRequest) (*git.DivergeObject, error) {
}
}()
- diff, err := git.GetDivergingCommits(tmpRepo, "base", "tracking")
+ diff, err := git.GetDivergingCommits(ctx, tmpRepo, "base", "tracking")
return &diff, err
}