Skip to content

Commit ec8ee95

Browse files
committed
improve code
1 parent d2f626c commit ec8ee95

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

services/gitdiff/gitdiff.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,15 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
683683

684684
// Get new file.
685685
if strings.HasPrefix(line, cmdDiffHead) {
686+
if len(diff.Files) >= maxFiles {
687+
diff.IsIncomplete = true
688+
_, err := io.Copy(ioutil.Discard, reader)
689+
if err != nil {
690+
return nil, fmt.Errorf("Copy: %v", err)
691+
}
692+
break
693+
}
694+
686695
var middle int
687696

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

719728
}
720729

721-
if len(diff.Files) >= maxFiles {
722-
diff.IsIncomplete = true
723-
_, err := io.Copy(ioutil.Discard, reader)
724-
if err != nil {
725-
return nil, fmt.Errorf("Copy: %v", err)
726-
}
727-
break
728-
}
729730
curFile = &DiffFile{
730731
Name: b,
731732
OldName: a,

0 commit comments

Comments
 (0)