Address issue #108 #109

Merged
bnavetta merged 15 commits from git_status into master 2014-09-11 02:16:39 -05:00
3 changed files with 0 additions and 54 deletions
Showing only changes of commit 33ae83f4d9 - Show all commits

View File

@ -3,14 +3,11 @@ 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
@ -170,26 +167,3 @@ 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
}

View File

@ -23,29 +23,6 @@ func TestStatusFile(t *testing.T) {
}
}
func TestStatusForeach(t *testing.T) {
repo := createTestRepo(t)
defer repo.Free()
defer os.RemoveAll(repo.Workdir())
err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644)
checkFatal(t, err)
statusFound := false
err = repo.StatusForeach(func (path string, statusFlags Status) int {
if path == "hello.txt" && statusFlags & StatusWtNew != 0 {
statusFound = true
}
return 0
});
checkFatal(t, err)
if !statusFound {
t.Fatal("Status callback not called with the new file")
}
}
func TestEntryCount(t *testing.T) {
repo := createTestRepo(t)
defer repo.Free()

View File

@ -105,9 +105,4 @@ int _go_git_blob_create_fromchunks(git_oid *id,
return git_blob_create_fromchunks(id, repo, hintpath, _go_blob_chunk_cb, payload);
}
int _go_git_status_foreach(git_repository *repo, void *data)
{
return git_status_foreach(repo, (git_status_cb)fileStatusForeach, data);
}
/* EOF */