Skip to content

Commit

Permalink
Give each const group a type
Browse files Browse the repository at this point in the history
This allows us to restrict which constants the compiler will allow
through, and makes the sorting in the documentation better.
  • Loading branch information
carlosmn committed Sep 12, 2013
1 parent 00e3df9 commit b5aca80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
9 changes: 5 additions & 4 deletions reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"unsafe"
)

type ReferenceType int
const (
ReferenceSymbolic = C.GIT_REF_SYMBOLIC
ReferenceOid = C.GIT_REF_OID
ReferenceSymbolic ReferenceType = C.GIT_REF_SYMBOLIC
ReferenceOid = C.GIT_REF_OID
)

type Reference struct {
Expand Down Expand Up @@ -103,8 +104,8 @@ func (v *Reference) Name() string {
return C.GoString(C.git_reference_name(v.ptr))
}

func (v *Reference) Type() int {
return int(C.git_reference_type(v.ptr))
func (v *Reference) Type() ReferenceType {
return ReferenceType(C.git_reference_type(v.ptr))
}

func (v *Reference) Free() {
Expand Down
2 changes: 1 addition & 1 deletion reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func compareStringList(t *testing.T, expected, actual []string) {
}
}

func checkRefType(t *testing.T, ref *Reference, kind int) {
func checkRefType(t *testing.T, ref *Reference, kind ReferenceType) {
if ref.Type() == kind {
return
}
Expand Down
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"unsafe"
)

type Filemode int
const (
FilemodeNew = C.GIT_FILEMODE_NEW
FilemodeNew Filemode = C.GIT_FILEMODE_NEW
FilemodeTree = C.GIT_FILEMODE_TREE
FilemodeBlob = C.GIT_FILEMODE_BLOB
FilemodeBlobExecutable = C.GIT_FILEMODE_BLOB_EXECUTABLE
Expand Down
11 changes: 6 additions & 5 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (

// RevWalk

type SortType uint
const (
SortNone = C.GIT_SORT_NONE
SortTopological = C.GIT_SORT_TOPOLOGICAL
SortTime = C.GIT_SORT_TIME
SortReverse = C.GIT_SORT_REVERSE
SortNone SortType = C.GIT_SORT_NONE
SortTopological = C.GIT_SORT_TOPOLOGICAL
SortTime = C.GIT_SORT_TIME
SortReverse = C.GIT_SORT_REVERSE
)

type RevWalk struct {
Expand Down Expand Up @@ -81,7 +82,7 @@ func (v *RevWalk) Iterate(fun RevWalkIterator) (err error) {
return nil
}

func (v *RevWalk) Sorting(sm uint) {
func (v *RevWalk) Sorting(sm SortType) {
C.git_revwalk_sorting(v.ptr, C.uint(sm))
}

Expand Down

0 comments on commit b5aca80

Please sign in to comment.