diff options
| author | David Calavera <[email protected]> | 2014-10-27 07:25:57 -0700 |
|---|---|---|
| committer | David Calavera <[email protected]> | 2014-10-27 07:25:57 -0700 |
| commit | 749d6149b31b17aab4ca58a2e48d73361547fc3e (patch) | |
| tree | efc5c075b9ac818918b388dc402875252a6202e0 /index.go | |
| parent | f6fa1a38abf7be7d4546b736e6db1ae7229e972f (diff) | |
| parent | 99d10775d66ffceca36c1fb0b947d8209f5153f8 (diff) | |
Merge branch 'master' into ls_remote
* master:
Update libgit2 submodule.
Remove Config#Refresh
implemented Index.AddAll, Index.RemoveAll, Index.UpdateAll
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 98 |
1 files changed, 98 insertions, 0 deletions
@@ -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)) |
