Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Nov 28, 2019
1 parent d2f626c commit ec8ee95
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,15 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D

// Get new file.
if strings.HasPrefix(line, cmdDiffHead) {
if len(diff.Files) >= maxFiles {
diff.IsIncomplete = true
_, err := io.Copy(ioutil.Discard, reader)
if err != nil {
return nil, fmt.Errorf("Copy: %v", err)
}
break
}

var middle int

// Note: In case file name is surrounded by double quotes (it happens only in git-shell).
Expand Down Expand Up @@ -718,14 +727,6 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D

}

if len(diff.Files) >= maxFiles {
diff.IsIncomplete = true
_, err := io.Copy(ioutil.Discard, reader)
if err != nil {
return nil, fmt.Errorf("Copy: %v", err)
}
break
}
curFile = &DiffFile{
Name: b,
OldName: a,
Expand Down

0 comments on commit ec8ee95

Please sign in to comment.