diff options
| author | Vicent Martà <[email protected]> | 2013-03-06 07:48:16 -0800 |
|---|---|---|
| committer | Vicent Martà <[email protected]> | 2013-03-06 07:48:16 -0800 |
| commit | bdfd8736bc8c119c4a841fd8b1c8202f5d5ceb9a (patch) | |
| tree | 287985309c887abb33b921239247e70420d40145 /index.go | |
| parent | 9b6d570748ae51bf38e3192f9a5de45bc68b23c6 (diff) | |
| parent | 23ba0f1e6dbfa75c71958f016b3e212d65143b60 (diff) | |
Merge pull request #4 from carlosmn/index
Wrap the index and test it a bit
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/index.go b/index.go new file mode 100644 index 0000000..72b1d5b --- /dev/null +++ b/index.go @@ -0,0 +1,49 @@ +package git + +/* +#cgo pkg-config: libgit2 +#include <git2.h> +#include <git2/errors.h> +*/ +import "C" +import ( + "runtime" + "unsafe" +) + +type Index struct { + ptr *C.git_index +} + +func newIndexFromC(ptr *C.git_index) *Index { + idx := &Index{ptr} + runtime.SetFinalizer(idx, (*Index).Free) + return idx +} + +func (v *Index) AddByPath(path string) error { + cstr := C.CString(path) + defer C.free(unsafe.Pointer(cstr)) + + ret := C.git_index_add_bypath(v.ptr, cstr) + if ret < 0 { + return LastError() + } + + return nil +} + +func (v *Index) WriteTree() (*Oid, error) { + oid := new(Oid) + ret := C.git_index_write_tree(oid.toC(), v.ptr) + if ret < 0 { + return nil, LastError() + } + + return oid, nil +} + +func (v *Index) Free() { + runtime.SetFinalizer(v, nil) + C.git_index_free(v.ptr) +} |
