@@ -37,6 +37,7 @@ import (
3737 "code.gitea.io/gitea/services/context"
3838 "code.gitea.io/gitea/services/convert"
3939 "code.gitea.io/gitea/services/forms"
40+ git_service "code.gitea.io/gitea/services/git"
4041 "code.gitea.io/gitea/services/gitdiff"
4142 issue_service "code.gitea.io/gitea/services/issue"
4243 notify_service "code.gitea.io/gitea/services/notify"
@@ -421,14 +422,14 @@ func CreatePullRequest(ctx *context.APIContext) {
421422 }
422423 defer closer ()
423424
424- if ! compareResult .baseRef .IsBranch () || ! compareResult .headRef .IsBranch () {
425+ if ! compareResult .BaseRef .IsBranch () || ! compareResult .HeadRef .IsBranch () {
425426 ctx .APIError (http .StatusUnprocessableEntity , "Invalid PullRequest: base and head must be branches" )
426427 return
427428 }
428429
429430 // Check if another PR exists with the same targets
430- existingPr , err := issues_model .GetUnmergedPullRequest (ctx , compareResult .headRepo .ID , ctx .Repo .Repository .ID ,
431- compareResult .headRef .ShortName (), compareResult .baseRef .ShortName (),
431+ existingPr , err := issues_model .GetUnmergedPullRequest (ctx , compareResult .HeadRepo .ID , ctx .Repo .Repository .ID ,
432+ compareResult .HeadRef .ShortName (), compareResult .BaseRef .ShortName (),
432433 issues_model .PullRequestFlowGithub ,
433434 )
434435 if err != nil {
@@ -506,13 +507,13 @@ func CreatePullRequest(ctx *context.APIContext) {
506507 DeadlineUnix : deadlineUnix ,
507508 }
508509 pr := & issues_model.PullRequest {
509- HeadRepoID : compareResult .headRepo .ID ,
510+ HeadRepoID : compareResult .HeadRepo .ID ,
510511 BaseRepoID : repo .ID ,
511- HeadBranch : compareResult .headRef .ShortName (),
512- BaseBranch : compareResult .baseRef .ShortName (),
513- HeadRepo : compareResult .headRepo ,
512+ HeadBranch : compareResult .HeadRef .ShortName (),
513+ BaseBranch : compareResult .BaseRef .ShortName (),
514+ HeadRepo : compareResult .HeadRepo ,
514515 BaseRepo : repo ,
515- MergeBase : compareResult .compareInfo . MergeBase ,
516+ MergeBase : compareResult .MergeBase ,
516517 Type : issues_model .PullRequestGitea ,
517518 }
518519
@@ -1058,16 +1059,8 @@ func MergePullRequest(ctx *context.APIContext) {
10581059 ctx .Status (http .StatusOK )
10591060}
10601061
1061- type parseCompareInfoResult struct {
1062- headRepo * repo_model.Repository
1063- headGitRepo * git.Repository
1064- compareInfo * pull_service.CompareInfo
1065- baseRef git.RefName
1066- headRef git.RefName
1067- }
1068-
10691062// parseCompareInfo returns non-nil if it succeeds, it always writes to the context and returns nil if it fails
1070- func parseCompareInfo (ctx * context.APIContext , compareParam string ) (result * parseCompareInfoResult , closer func ()) {
1063+ func parseCompareInfo (ctx * context.APIContext , compareParam string ) (result * git_service. CompareInfo , closer func ()) {
10711064 baseRepo := ctx .Repo .Repository
10721065 compareReq , err := common .ParseCompareRouterParam (compareParam )
10731066 switch {
@@ -1157,14 +1150,13 @@ func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *par
11571150 return nil , nil
11581151 }
11591152
1160- compareInfo , err := pull_service .GetCompareInfo (ctx , baseRepo , headRepo , headGitRepo , baseRef . ShortName () , headRef . ShortName () , compareReq .DirectComparison (), false )
1153+ compareInfo , err := git_service .GetCompareInfo (ctx , baseRepo , headRepo , headGitRepo , baseRef , headRef , compareReq .DirectComparison (), false )
11611154 if err != nil {
11621155 ctx .APIErrorInternal (err )
11631156 return nil , nil
11641157 }
11651158
1166- result = & parseCompareInfoResult {headRepo : headRepo , headGitRepo : headGitRepo , compareInfo : compareInfo , baseRef : baseRef , headRef : headRef }
1167- return result , closer
1159+ return compareInfo , closer
11681160}
11691161
11701162// UpdatePullRequest merge PR's baseBranch into headBranch
@@ -1408,7 +1400,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
14081400 return
14091401 }
14101402
1411- var prInfo * pull_service .CompareInfo
1403+ var compareInfo * git_service .CompareInfo
14121404 baseGitRepo , closer , err := gitrepo .RepositoryFromContextOrOpen (ctx , pr .BaseRepo )
14131405 if err != nil {
14141406 ctx .APIErrorInternal (err )
@@ -1417,19 +1409,18 @@ func GetPullRequestCommits(ctx *context.APIContext) {
14171409 defer closer .Close ()
14181410
14191411 if pr .HasMerged {
1420- prInfo , err = pull_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , pr .MergeBase , pr .GetGitHeadRefName (), false , false )
1412+ compareInfo , err = git_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , git . RefName ( pr .MergeBase ), git . RefName ( pr .GetGitHeadRefName () ), false , false )
14211413 } else {
1422- prInfo , err = pull_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , pr .BaseBranch , pr .GetGitHeadRefName (), false , false )
1414+ compareInfo , err = git_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , git . RefNameFromBranch ( pr .BaseBranch ), git . RefName ( pr .GetGitHeadRefName () ), false , false )
14231415 }
14241416 if err != nil {
14251417 ctx .APIErrorInternal (err )
14261418 return
14271419 }
1428- commits := prInfo .Commits
14291420
14301421 listOptions := utils .GetListOptions (ctx )
14311422
1432- totalNumberOfCommits := len (commits )
1423+ totalNumberOfCommits := len (compareInfo . Commits )
14331424 totalNumberOfPages := int (math .Ceil (float64 (totalNumberOfCommits ) / float64 (listOptions .PageSize )))
14341425
14351426 userCache := make (map [string ]* user_model.User )
@@ -1444,7 +1435,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
14441435
14451436 apiCommits := make ([]* api.Commit , 0 , limit )
14461437 for i := start ; i < start + limit ; i ++ {
1447- apiCommit , err := convert .ToCommit (ctx , ctx .Repo .Repository , baseGitRepo , commits [i ], userCache ,
1438+ apiCommit , err := convert .ToCommit (ctx , ctx .Repo .Repository , baseGitRepo , compareInfo . Commits [i ], userCache ,
14481439 convert.ToCommitOptions {
14491440 Stat : true ,
14501441 Verification : verification ,
@@ -1538,11 +1529,11 @@ func GetPullRequestFiles(ctx *context.APIContext) {
15381529
15391530 baseGitRepo := ctx .Repo .GitRepo
15401531
1541- var prInfo * pull_service .CompareInfo
1532+ var compareInfo * git_service .CompareInfo
15421533 if pr .HasMerged {
1543- prInfo , err = pull_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , pr .MergeBase , pr .GetGitHeadRefName (), true , false )
1534+ compareInfo , err = git_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , git . RefName ( pr .MergeBase ), git . RefName ( pr .GetGitHeadRefName () ), true , false )
15441535 } else {
1545- prInfo , err = pull_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , pr .BaseBranch , pr .GetGitHeadRefName (), true , false )
1536+ compareInfo , err = git_service .GetCompareInfo (ctx , pr .BaseRepo , pr .BaseRepo , baseGitRepo , git . RefNameFromBranch ( pr .BaseBranch ), git . RefName ( pr .GetGitHeadRefName () ), true , false )
15461537 }
15471538 if err != nil {
15481539 ctx .APIErrorInternal (err )
@@ -1555,7 +1546,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
15551546 return
15561547 }
15571548
1558- startCommitID := prInfo .MergeBase
1549+ startCommitID := compareInfo .MergeBase
15591550 endCommitID := headCommitID
15601551
15611552 maxLines := setting .Git .MaxGitDiffLines
0 commit comments