diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-01-06 18:00:40 -0200 |
---|---|---|
committer | Andrey Nering <andrey.nering@gmail.com> | 2016-01-06 18:00:40 -0200 |
commit | 81ed5c4bee112beacd8e0f34b336b4f3b6c6a6c1 (patch) | |
tree | e3848afc72fa6328cd18ee7ca3414f552c25cd51 /models/git_diff.go | |
parent | 73474c043bfdeeb33cd58bdfe42592fea3083422 (diff) | |
download | gitea-81ed5c4bee112beacd8e0f34b336b4f3b6c6a6c1.tar.gz gitea-81ed5c4bee112beacd8e0f34b336b4f3b6c6a6c1.zip |
Declaring specific types for enums constants.
This makes the code more strict since you can't assign or compare
values of different types without proper cast.
Diffstat (limited to 'models/git_diff.go')
-rw-r--r-- | models/git_diff.go | 35 |
1 files changed, 21 insertions, 14 deletions
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. +type DiffLineType uint8 + const ( - DIFF_LINE_PLAIN = iota + 1 - DIFF_LINE_ADD - DIFF_LINE_DEL - DIFF_LINE_SECTION + 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 = iota + 1 - DIFF_FILE_CHANGE - DIFF_FILE_DEL - DIFF_FILE_RENAME + 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 |