@@ -239,9 +239,11 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
239
239
// Calculate diff
240
240
startCommitID = pr .MergeBase
241
241
242
- apiPullRequest . ChangedFiles , apiPullRequest . Additions , apiPullRequest . Deletions , err = gitRepo .GetDiffShortStat (startCommitID , endCommitID )
242
+ diffChangedFiles , diffAdditions , diffDeletions , err : = gitRepo .GetDiffShortStat (startCommitID , endCommitID )
243
243
if err != nil {
244
244
log .Error ("GetDiffShortStat: %v" , err )
245
+ } else {
246
+ apiPullRequest .ChangedFiles , apiPullRequest .Additions , apiPullRequest .Deletions = & diffChangedFiles , & diffAdditions , & diffDeletions
245
247
}
246
248
}
247
249
@@ -459,12 +461,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
459
461
return nil , err
460
462
}
461
463
462
- // Outer scope variables to be used in diff calculation
463
- var (
464
- startCommitID string
465
- endCommitID string
466
- )
467
-
468
464
if git .IsErrBranchNotExist (err ) {
469
465
headCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
470
466
if err != nil && ! git .IsErrNotExist (err ) {
@@ -473,7 +469,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
473
469
}
474
470
if err == nil {
475
471
apiPullRequest .Head .Sha = headCommitID
476
- endCommitID = headCommitID
477
472
}
478
473
} else {
479
474
commit , err := headBranch .GetCommit ()
@@ -484,17 +479,8 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
484
479
if err == nil {
485
480
apiPullRequest .Head .Ref = pr .HeadBranch
486
481
apiPullRequest .Head .Sha = commit .ID .String ()
487
- endCommitID = commit .ID .String ()
488
482
}
489
483
}
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
- }
498
484
}
499
485
500
486
if len (apiPullRequest .Head .Sha ) == 0 && len (apiPullRequest .Head .Ref ) != 0 {
0 commit comments