summaryrefslogtreecommitdiff
path: root/status.go
diff options
context:
space:
mode:
authorBen Navetta <[email protected]>2014-08-19 08:51:18 -0400
committerBen Navetta <[email protected]>2014-08-19 08:51:18 -0400
commit1cb654e4f2ae536f71773dbe0bd808874b832d9c (patch)
treeaa5f387735b6db75ed1b9ae8e52c3ba436fd4557 /status.go
parentfe1e6b83edfa8456f6ed8eb83eaa6fe57771e875 (diff)
add git_status_foreach binding
Diffstat (limited to 'status.go')
-rw-r--r--status.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/status.go b/status.go
index ab0469f..4523cb8 100644
--- a/status.go
+++ b/status.go
@@ -3,11 +3,14 @@ package git
/*
#include <git2.h>
#include <git2/errors.h>
+
+int _go_git_status_foreach(git_repository *repo, void *data);
*/
import "C"
import (
"runtime"
+ "unsafe"
)
type Status int
@@ -168,3 +171,26 @@ func (v *Repository) StatusFile(path string) (Status, error) {
}
return Status(statusFlags), nil
}
+
+type StatusCallback func(path string, status Status) int
+
+//export fileStatusForeach
+func fileStatusForeach(_path *C.char, _flags C.uint, _payload unsafe.Pointer) C.int {
+ path := C.GoString(_path)
+ flags := Status(_flags)
+
+ cb := (*StatusCallback)(_payload)
+ return C.int((*cb)(path, flags))
+}
+
+func (v *Repository) StatusForeach(callback StatusCallback) error {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C._go_git_status_foreach(v.ptr, unsafe.Pointer(&callback))
+
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
+}