@ -28,6 +28,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/references"
@ -165,9 +166,10 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
go AddTestPullRequestTask ( doer , pr . BaseRepo . ID , pr . BaseBranch , false , "" , "" )
go AddTestPullRequestTask ( doer , pr . BaseRepo . ID , pr . BaseBranch , false , "" , "" )
} ( )
} ( )
// TODO: make it able to do this in a database session
// Run the merge in the hammer context to prevent cancellation
mergeCtx := context . Background ( )
hammerCtx := graceful . GetManager ( ) . HammerContext ( )
pr . MergedCommitID , err = rawMerge ( mergeCtx , pr , doer , mergeStyle , expectedHeadCommitID , message )
pr . MergedCommitID , err = rawMerge ( hammerCtx , pr , doer , mergeStyle , expectedHeadCommitID , message )
if err != nil {
if err != nil {
return err
return err
}
}
@ -176,18 +178,18 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
pr . Merger = doer
pr . Merger = doer
pr . MergerID = doer . ID
pr . MergerID = doer . ID
if _ , err := pr . SetMerged ( c tx) ; err != nil {
if _ , err := pr . SetMerged ( hammerC tx) ; err != nil {
log . Error ( "setMerged [%d]: %v" , pr . ID , err )
log . Error ( "setMerged [%d]: %v" , pr . ID , err )
}
}
if err := pr . LoadIssueCtx ( c tx) ; err != nil {
if err := pr . LoadIssueCtx ( hammerC tx) ; err != nil {
log . Error ( "loadIssue [%d]: %v" , pr . ID , err )
log . Error ( "loadIssue [%d]: %v" , pr . ID , err )
}
}
if err := pr . Issue . LoadRepo ( c tx) ; err != nil {
if err := pr . Issue . LoadRepo ( hammerC tx) ; err != nil {
log . Error ( "loadRepo for issue [%d]: %v" , pr . ID , err )
log . Error ( "loadRepo for issue [%d]: %v" , pr . ID , err )
}
}
if err := pr . Issue . Repo . GetOwner ( c tx) ; err != nil {
if err := pr . Issue . Repo . GetOwner ( hammerC tx) ; err != nil {
log . Error ( "GetOwner for issue repo [%d]: %v" , pr . ID , err )
log . Error ( "GetOwner for issue repo [%d]: %v" , pr . ID , err )
}
}
@ -197,17 +199,17 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
cache . Remove ( pr . Issue . Repo . GetCommitsCountCacheKey ( pr . BaseBranch , true ) )
cache . Remove ( pr . Issue . Repo . GetCommitsCountCacheKey ( pr . BaseBranch , true ) )
// Resolve cross references
// Resolve cross references
refs , err := pr . ResolveCrossReferences ( c tx)
refs , err := pr . ResolveCrossReferences ( hammerC tx)
if err != nil {
if err != nil {
log . Error ( "ResolveCrossReferences: %v" , err )
log . Error ( "ResolveCrossReferences: %v" , err )
return nil
return nil
}
}
for _ , ref := range refs {
for _ , ref := range refs {
if err = ref . LoadIssueCtx ( c tx) ; err != nil {
if err = ref . LoadIssueCtx ( hammerC tx) ; err != nil {
return err
return err
}
}
if err = ref . Issue . LoadRepo ( c tx) ; err != nil {
if err = ref . Issue . LoadRepo ( hammerC tx) ; err != nil {
return err
return err
}
}
close := ref . RefAction == references . XRefActionCloses
close := ref . RefAction == references . XRefActionCloses