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
367 367
368// Diff represents a difference between two git trees.368// Diff represents a difference between two git trees.
369type Diff struct {369type Diff struct {
370 TotalAddition, TotalDeletion int370 NumFiles, TotalAddition, TotalDeletion int
371 Files []*DiffFile371 Files []*DiffFile
372 IsIncomplete bool372 IsIncomplete bool
373}373}
374 374
375// LoadComments loads comments into each line375// LoadComments loads comments into each line
@@ -398,11 +398,6 @@ func (diff *Diff) LoadComments(issue *models.Issue, currentUser *models.User) er · 22 unmodified lines
398 return nil398 return nil
399}399}
400 400
401// NumFiles returns number of files changes in a diff.
402func (diff *Diff) NumFiles() int {
403 return len(diff.Files)
404}
405
406const cmdDiffHead = "diff --git "401const cmdDiffHead = "diff --git "
407 402
408// ParsePatch builds a Diff object from a io.Reader and some403// 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
639 }634 }
640 }635 }
641 }636 }
642 637 diff.NumFiles = len(diff.Files)
643 return diff, nil638 return diff, nil
644}639}
645 640
@@ -716,6 +711,11 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID · 70 unmodified lines
716 return nil, fmt.Errorf("Wait: %v", err)711 return nil, fmt.Errorf("Wait: %v", err)
717 }712 }
718 713
714 diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(repoPath, beforeCommitID+"..."+afterCommitID)
715 if err != nil {
716 return nil, err
717 }
718
719 return diff, nil719 return diff, nil
720}720}
721 721