@@ -239,9 +239,11 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
239239 // Calculate diff
240240 startCommitID = pr .MergeBase
241241
242- apiPullRequest . ChangedFiles , apiPullRequest . Additions , apiPullRequest . Deletions , err = gitRepo .GetDiffShortStat (startCommitID , endCommitID )
242+ diffChangedFiles , diffAdditions , diffDeletions , err : = gitRepo .GetDiffShortStat (startCommitID , endCommitID )
243243 if err != nil {
244244 log .Error ("GetDiffShortStat: %v" , err )
245+ } else {
246+ apiPullRequest .ChangedFiles , apiPullRequest .Additions , apiPullRequest .Deletions = & diffChangedFiles , & diffAdditions , & diffDeletions
245247 }
246248 }
247249
@@ -459,12 +461,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
459461 return nil , err
460462 }
461463
462- // Outer scope variables to be used in diff calculation
463- var (
464- startCommitID string
465- endCommitID string
466- )
467-
468464 if git .IsErrBranchNotExist (err ) {
469465 headCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
470466 if err != nil && ! git .IsErrNotExist (err ) {
@@ -473,7 +469,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
473469 }
474470 if err == nil {
475471 apiPullRequest .Head .Sha = headCommitID
476- endCommitID = headCommitID
477472 }
478473 } else {
479474 commit , err := headBranch .GetCommit ()
@@ -484,17 +479,8 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
484479 if err == nil {
485480 apiPullRequest .Head .Ref = pr .HeadBranch
486481 apiPullRequest .Head .Sha = commit .ID .String ()
487- endCommitID = commit .ID .String ()
488482 }
489483 }
490-
491- // Calculate diff
492- startCommitID = pr .MergeBase
493-
494- apiPullRequest .ChangedFiles , apiPullRequest .Additions , apiPullRequest .Deletions , err = gitRepo .GetDiffShortStat (startCommitID , endCommitID )
495- if err != nil {
496- log .Error ("GetDiffShortStat: %v" , err )
497- }
498484 }
499485
500486 if len (apiPullRequest .Head .Sha ) == 0 && len (apiPullRequest .Head .Ref ) != 0 {
0 commit comments