summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-10-25 18:11:52 +0200
committerCarlos Martín Nieto <[email protected]>2014-10-25 18:11:52 +0200
commit99d10775d66ffceca36c1fb0b947d8209f5153f8 (patch)
tree26ed31d1201a303b5a2d004a64d9d2846b9ca25e /index.go
parenta2fd47aad228914235b0eecf8984099aea7c1b38 (diff)
parent9d37f817648cac252194816751cd383ae3586883 (diff)
Merge pull request #125 from lucas-clemente/master
implemented Index.AddAll as git_index_add_all wrapper
Diffstat (limited to 'index.go')
-rw-r--r--index.go98
1 files changed, 98 insertions, 0 deletions
diff --git a/index.go b/index.go
index 289239d..230e159 100644
--- a/index.go
+++ b/index.go
@@ -3,6 +3,11 @@ package git
/*
#include <git2.h>
#include <git2/errors.h>
+
+extern int _go_git_index_add_all(git_index*, const git_strarray*, unsigned int, void*);
+extern int _go_git_index_update_all(git_index*, const git_strarray*, void*);
+extern int _go_git_index_remove_all(git_index*, const git_strarray*, void*);
+
*/
import "C"
import (
@@ -12,6 +17,17 @@ import (
"unsafe"
)
+type IndexMatchedPathCallback func(string, string) int
+
+type IndexAddOpts uint
+
+const (
+ IndexAddDefault IndexAddOpts = C.GIT_INDEX_ADD_DEFAULT
+ IndexAddForce IndexAddOpts = C.GIT_INDEX_ADD_FORCE
+ IndexAddDisablePathspecMatch IndexAddOpts = C.GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH
+ IndexAddCheckPathspec IndexAddOpts = C.GIT_INDEX_ADD_CHECK_PATHSPEC
+)
+
type Index struct {
ptr *C.git_index
}
@@ -114,6 +130,88 @@ func (v *Index) AddByPath(path string) error {
return nil
}
+func (v *Index) AddAll(pathspecs []string, flags IndexAddOpts, callback IndexMatchedPathCallback) error {
+ cpathspecs := C.git_strarray{}
+ cpathspecs.count = C.size_t(len(pathspecs))
+ cpathspecs.strings = makeCStringsFromStrings(pathspecs)
+ defer freeStrarray(&cpathspecs)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var cb *IndexMatchedPathCallback
+ if callback != nil {
+ cb = &callback
+ }
+
+ ret := C._go_git_index_add_all(
+ v.ptr,
+ &cpathspecs,
+ C.uint(flags),
+ unsafe.Pointer(cb),
+ )
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
+}
+
+func (v *Index) UpdateAll(pathspecs []string, callback IndexMatchedPathCallback) error {
+ cpathspecs := C.git_strarray{}
+ cpathspecs.count = C.size_t(len(pathspecs))
+ cpathspecs.strings = makeCStringsFromStrings(pathspecs)
+ defer freeStrarray(&cpathspecs)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var cb *IndexMatchedPathCallback
+ if callback != nil {
+ cb = &callback
+ }
+
+ ret := C._go_git_index_update_all(
+ v.ptr,
+ &cpathspecs,
+ unsafe.Pointer(cb),
+ )
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
+}
+
+func (v *Index) RemoveAll(pathspecs []string, callback IndexMatchedPathCallback) error {
+ cpathspecs := C.git_strarray{}
+ cpathspecs.count = C.size_t(len(pathspecs))
+ cpathspecs.strings = makeCStringsFromStrings(pathspecs)
+ defer freeStrarray(&cpathspecs)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var cb *IndexMatchedPathCallback
+ if callback != nil {
+ cb = &callback
+ }
+
+ ret := C._go_git_index_remove_all(
+ v.ptr,
+ &cpathspecs,
+ unsafe.Pointer(cb),
+ )
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
+}
+
+//export indexMatchedPathCallback
+func indexMatchedPathCallback(cPath, cMatchedPathspec *C.char, payload unsafe.Pointer) int {
+ callback := (*IndexMatchedPathCallback)(payload)
+ return (*callback)(C.GoString(cPath), C.GoString(cMatchedPathspec))
+}
+
func (v *Index) RemoveByPath(path string) error {
cstr := C.CString(path)
defer C.free(unsafe.Pointer(cstr))