mirror of
https://github.com/go-gitea/gitea
synced 2025-07-15 23:17:19 +00:00
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user