diff options
| author | Ben Navetta <[email protected]> | 2014-08-19 08:51:18 -0400 |
|---|---|---|
| committer | Ben Navetta <[email protected]> | 2014-08-19 08:51:18 -0400 |
| commit | 1cb654e4f2ae536f71773dbe0bd808874b832d9c (patch) | |
| tree | aa5f387735b6db75ed1b9ae8e52c3ba436fd4557 /status.go | |
| parent | fe1e6b83edfa8456f6ed8eb83eaa6fe57771e875 (diff) | |
add git_status_foreach binding
Diffstat (limited to 'status.go')
| -rw-r--r-- | status.go | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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 +} |
