History

Fix numbr of files, total additions, and deletions (#11614)

Signed-off-by: Andrew Thornton <art27@cantab.net>

zeripath committed 6 years ago

Commit 5cb201d1 parent b97917a8 files · +106 −15Browse files

Showing the changes to services/gitdiff/gitdiff.go (1 of 8 files). Show all

Unified · Split

services/gitdiff/gitdiff.go+9−9
@@ -367,9 +367,9 @@ func getCommitFileLineCount(commit *git.Commit, filePath string) int { · 366 unmodified lines
367367
368368 // Diff represents a difference between two git trees.
369369 type Diff struct {
370− TotalAddition, TotalDeletion int
371− Files []*DiffFile
372− IsIncomplete bool
370+ NumFiles, TotalAddition, TotalDeletion int
371+ Files []*DiffFile
372+ IsIncomplete bool
373373 }
374374
375375 // LoadComments loads comments into each line
@@ -398,11 +398,6 @@ func (diff *Diff) LoadComments(issue *models.Issue, currentUser *models.User) er · 22 unmodified lines
398398 return nil
399399 }
400400
401−// NumFiles returns number of files changes in a diff.
402−func (diff *Diff) NumFiles() int {
403− return len(diff.Files)
404−}
405−
406401 const cmdDiffHead = "diff --git "
407402
408403 // ParsePatch builds a Diff object from a io.Reader and some
@@ -639,7 +634,7 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D · 230 unmodified lines
639634 }
640635 }
641636 }
642−
637+ diff.NumFiles = len(diff.Files)
643638 return diff, nil
644639 }
645640
@@ -716,6 +711,11 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID · 70 unmodified lines
716711 return nil, fmt.Errorf("Wait: %v", err)
717712 }
718713
714+ diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, beforeCommitID+"..."+afterCommitID)
715+ if err != nil {
716+ return nil, err
717+ }
718+
719719 return diff, nil
720720 }
721721