Address issue #108 #109
26
status.go
26
status.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue