summaryrefslogtreecommitdiffstats
path: root/models/git_diff.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-15 20:01:20 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-15 20:01:20 -0400
commitc3a52f7dd075f1f3cf7fb935b7489629760837ab (patch)
treeab27cc4a5cc1d10c366bcfd04585f02fccb8176b /models/git_diff.go
parent67426534ef9f0ceba49330cbc0b7676f4009a6e1 (diff)
downloadgitea-c3a52f7dd075f1f3cf7fb935b7489629760837ab.tar.gz
gitea-c3a52f7dd075f1f3cf7fb935b7489629760837ab.zip
Mirror bug fix on downloading zip
Diffstat (limited to 'models/git_diff.go')
-rw-r--r--models/git_diff.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index de9d1de7b1..cf93af6959 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -51,6 +51,7 @@ type DiffFile struct {
Name string
Addition, Deletion int
Type int
+ IsBin bool
Sections []*DiffSection
}
@@ -96,13 +97,15 @@ func ParsePatch(reader io.Reader) (*Diff, error) {
if line == "" {
continue
}
- if line[0] == ' ' {
+
+ switch {
+ case line[0] == ' ':
diffLine := &DiffLine{Type: DIFF_LINE_PLAIN, Content: line, LeftIdx: leftLine, RightIdx: rightLine}
leftLine++
rightLine++
curSection.Lines = append(curSection.Lines, diffLine)
continue
- } else if line[0] == '@' {
+ case line[0] == '@':
curSection = &DiffSection{}
curFile.Sections = append(curFile.Sections, curSection)
ss := strings.Split(line, "@@")
@@ -114,14 +117,14 @@ func ParsePatch(reader io.Reader) (*Diff, error) {
leftLine, _ = base.StrTo(strings.Split(ranges[0], ",")[0][1:]).Int()
rightLine, _ = base.StrTo(strings.Split(ranges[1], ",")[0]).Int()
continue
- } else if line[0] == '+' {
+ case line[0] == '+':
curFile.Addition++
diff.TotalAddition++
diffLine := &DiffLine{Type: DIFF_LINE_ADD, Content: line, RightIdx: rightLine}
rightLine++
curSection.Lines = append(curSection.Lines, diffLine)
continue
- } else if line[0] == '-' {
+ case line[0] == '-':
curFile.Deletion++
diff.TotalDeletion++
diffLine := &DiffLine{Type: DIFF_LINE_DEL, Content: line, LeftIdx: leftLine}
@@ -129,6 +132,8 @@ func ParsePatch(reader io.Reader) (*Diff, error) {
leftLine++
}
curSection.Lines = append(curSection.Lines, diffLine)
+ case strings.HasPrefix(line, "Binary"):
+ curFile.IsBin = true
continue
}