Skip to content

Commit 40bd121

Browse files
committed
use name GetDiffShortStatByCmdArgs, fix comments
1 parent 58d24ab commit 40bd121

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

modules/git/repo_compare.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
176176

177177
// GetDiffShortStat counts number of changed files, number of additions and deletions
178178
func (repo *Repository) GetDiffShortStat(base, head string) (numFiles, totalAdditions, totalDeletions int, err error) {
179-
numFiles, totalAdditions, totalDeletions, err = GetDiffWithShortStat(repo.Ctx, repo.Path, nil, base+"..."+head)
179+
numFiles, totalAdditions, totalDeletions, err = GetDiffShortStatByCmdArgs(repo.Ctx, repo.Path, nil, base+"..."+head)
180180
if err != nil && strings.Contains(err.Error(), "no merge base") {
181-
return GetDiffWithShortStat(repo.Ctx, repo.Path, nil, base, head)
181+
return GetDiffShortStatByCmdArgs(repo.Ctx, repo.Path, nil, base, head)
182182
}
183183
return numFiles, totalAdditions, totalDeletions, err
184184
}
185185

186-
// GetDiffWithShortStat counts number of changed files, number of additions and deletions
187-
func GetDiffWithShortStat(ctx context.Context, repoPath string, trustedArgs TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error) {
186+
// GetDiffShortStatByCmdArgs counts number of changed files, number of additions and deletions
187+
// TODO: there are already 2 other different "GetDiffShortStat" functions in code base, they do similar things, need to refactor in the future
188+
func GetDiffShortStatByCmdArgs(ctx context.Context, repoPath string, trustedArgs TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error) {
188189
// Now if we call:
189190
// $ git diff --shortstat 1ebb35b98889ff77299f24d82da426b434b0cca0...788b8b1440462d477f45b0088875
190191
// we get:

routers/web/repo/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func GetPullDiffStats(ctx *context.Context) {
202202

203203
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, mergeBaseCommitID, headCommitID)
204204
if err != nil {
205-
ctx.ServerError("GetDiffWithShortStat", err)
205+
ctx.ServerError("GetDiffShortStat", err)
206206
return
207207
}
208208

@@ -773,7 +773,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
773773

774774
diffShortStat, err := gitdiff.GetDiffShortStat(ctx.Repo.GitRepo, startCommitID, endCommitID)
775775
if err != nil {
776-
ctx.ServerError("GetDiffWithShortStat", err)
776+
ctx.ServerError("GetDiffShortStat", err)
777777
return
778778
}
779779
ctx.Data["DiffShortStat"] = diffShortStat

services/convert/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
494494
// Calculate diff
495495
startCommitID = pr.MergeBase
496496

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
497499
apiPullRequest.ChangedFiles, apiPullRequest.Additions, apiPullRequest.Deletions, err = gitRepo.GetDiffShortStat(startCommitID, endCommitID)
498500
if err != nil {
499501
log.Error("GetDiffShortStat: %v", err)

services/gitdiff/gitdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ func GetDiffShortStat(gitRepo *git.Repository, beforeCommitID, afterCommitID str
12441244
}
12451245

12461246
diff := &DiffShortStat{}
1247-
diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffWithShortStat(gitRepo.Ctx, repoPath, nil, actualBeforeCommitID.String(), afterCommitID)
1247+
diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStatByCmdArgs(gitRepo.Ctx, repoPath, nil, actualBeforeCommitID.String(), afterCommitID)
12481248
if err != nil {
12491249
return nil, err
12501250
}

0 commit comments

Comments
 (0)