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