summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2013-09-12 10:46:20 +0200
committerCarlos Martín Nieto <[email protected]>2013-09-12 10:46:20 +0200
commitb5aca803db4cf9adce0a037cc5ccc47c4c045510 (patch)
tree0280a0e5148bff28de858393bdfc1e1420d3b799
parent00e3df94c7e06ab66fe4618d3252458163e4a404 (diff)
Give each const group a type
This allows us to restrict which constants the compiler will allow through, and makes the sorting in the documentation better.
-rw-r--r--reference.go9
-rw-r--r--reference_test.go2
-rw-r--r--tree.go3
-rw-r--r--walk.go11
4 files changed, 14 insertions, 11 deletions
diff --git a/reference.go b/reference.go
index fae676f..86e9ee0 100644
--- a/reference.go
+++ b/reference.go
@@ -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 {
@@ -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() {
diff --git a/reference_test.go b/reference_test.go
index 36387ee..b2acba7 100644
--- a/reference_test.go
+++ b/reference_test.go
@@ -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
}
diff --git a/tree.go b/tree.go
index d1a7c59..3abd31c 100644
--- a/tree.go
+++ b/tree.go
@@ -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
diff --git a/walk.go b/walk.go
index 1d560b6..6525db1 100644
--- a/walk.go
+++ b/walk.go
@@ -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 {
@@ -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))
}