Skip to content

Commit 081f2f0

Browse files
committed
do not run "git diff --shortstat" for pull list
1 parent 40bd121 commit 081f2f0

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

modules/structs/pull.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ type PullRequest struct {
2525
Draft bool `json:"draft"`
2626
IsLocked bool `json:"is_locked"`
2727
Comments int `json:"comments"`
28+
2829
// number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)
29-
ReviewComments int `json:"review_comments"`
30-
Additions int `json:"additions"`
31-
Deletions int `json:"deletions"`
32-
ChangedFiles int `json:"changed_files"`
30+
ReviewComments int `json:"review_comments,omitempty"`
31+
32+
Additions *int `json:"additions,omitempty"`
33+
Deletions *int `json:"deletions,omitempty"`
34+
ChangedFiles *int `json:"changed_files,omitempty"`
3335

3436
HTMLURL string `json:"html_url"`
3537
DiffURL string `json:"diff_url"`

services/convert/pull.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/gitea/modules/log"
2020
api "code.gitea.io/gitea/modules/structs"
2121
"code.gitea.io/gitea/modules/util"
22+
"code.gitea.io/gitea/services/gitdiff"
2223
)
2324

2425
// ToAPIPullRequest assumes following fields have been assigned with valid values:
@@ -239,9 +240,13 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
239240
// Calculate diff
240241
startCommitID = pr.MergeBase
241242

242-
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
243+
diffShortStats, err := gitdiff.GetDiffShortStat(gitRepo, startCommitID, endCommitID)
243244
if err != nil {
244245
log.Error("GetDiffShortStat: %v", err)
246+
} else {
247+
apiPullRequest.ChangedFiles = &diffShortStats.NumFiles
248+
apiPullRequest.Additions = &diffShortStats.TotalAddition
249+
apiPullRequest.Deletions = &diffShortStats.TotalDeletion
245250
}
246251
}
247252

@@ -462,12 +467,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
462467
return nil, err
463468
}
464469

465-
// Outer scope variables to be used in diff calculation
466-
var (
467-
startCommitID string
468-
endCommitID string
469-
)
470-
471470
if git.IsErrBranchNotExist(err) {
472471
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
473472
if err != nil && !git.IsErrNotExist(err) {
@@ -476,7 +475,6 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
476475
}
477476
if err == nil {
478477
apiPullRequest.Head.Sha = headCommitID
479-
endCommitID = headCommitID
480478
}
481479
} else {
482480
commit, err := headBranch.GetCommit()
@@ -487,19 +485,8 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
487485
if err == nil {
488486
apiPullRequest.Head.Ref = pr.HeadBranch
489487
apiPullRequest.Head.Sha = commit.ID.String()
490-
endCommitID = commit.ID.String()
491488
}
492489
}
493-
494-
// Calculate diff
495-
startCommitID = pr.MergeBase
496-
497-
// FIXME: it causes performance regressions, because in many cases end users do not need these information
498-
// But "git diff --shortstat" is slow on large repositories, this call makes the API slow
499-
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
500-
if err != nil {
501-
log.Error("GetDiffShortStat: %v", err)
502-
}
503490
}
504491

505492
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {

0 commit comments

Comments
 (0)