diff --git a/models/git_diff.go b/models/git_diff.go index 9656813bf8..2b9bda2531 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -28,31 +28,34 @@ import ( "github.com/sergi/go-diff/diffmatchpatch" ) -// Diff line types. -const ( - DIFF_LINE_PLAIN = iota + 1 - DIFF_LINE_ADD - DIFF_LINE_DEL - DIFF_LINE_SECTION -) +type DiffLineType uint8 const ( - DIFF_FILE_ADD = iota + 1 - DIFF_FILE_CHANGE - DIFF_FILE_DEL - DIFF_FILE_RENAME + DIFF_LINE_PLAIN DiffLineType = iota + 1 + DIFF_LINE_ADD DiffLineType = iota + 1 + DIFF_LINE_DEL DiffLineType = iota + 1 + DIFF_LINE_SECTION DiffLineType = iota + 1 +) + +type DiffFileType uint8 + +const ( + DIFF_FILE_ADD DiffFileType = iota + 1 + DIFF_FILE_CHANGE DiffFileType = iota + 1 + DIFF_FILE_DEL DiffFileType = iota + 1 + DIFF_FILE_RENAME DiffFileType = iota + 1 ) type DiffLine struct { LeftIdx int RightIdx int - Type int + Type DiffLineType Content string ParsedContent template.HTML } -func (d DiffLine) GetType() int { - return d.Type +func (d *DiffLine) GetType() int { + return int(d.Type) } type DiffSection struct { @@ -60,7 +63,7 @@ type DiffSection struct { Lines []*DiffLine } -func diffToHtml(diffRecord []diffmatchpatch.Diff, lineType int) template.HTML { +func diffToHtml(diffRecord []diffmatchpatch.Diff, lineType DiffLineType) template.HTML { result := "" for _, s := range diffRecord { if s.Type == diffmatchpatch.DiffInsert && lineType == DIFF_LINE_ADD { @@ -146,7 +149,7 @@ type DiffFile struct { OldName string Index int Addition, Deletion int - Type int + Type DiffFileType IsCreated bool IsDeleted bool IsBin bool @@ -154,6 +157,10 @@ type DiffFile struct { Sections []*DiffSection } +func (diffFile *DiffFile) GetType() int { + return int(diffFile.Type) +} + type Diff struct { TotalAddition, TotalDeletion int Files []*DiffFile diff --git a/templates/repo/diff_box.tmpl b/templates/repo/diff_box.tmpl index f7851822f0..a3245d1c2b 100644 --- a/templates/repo/diff_box.tmpl +++ b/templates/repo/diff_box.tmpl @@ -26,7 +26,7 @@ {{end}} - + {{.Name}} {{end}} @@ -71,7 +71,7 @@ {{if $.IsSplitStyle}} {{range $j, $section := .Sections}} {{range $k, $line := .Lines}} -