diff options
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -66,6 +66,39 @@ func newIndexFromC(ptr *C.git_index) *Index { return idx } +// NewIndex allocates a new index. It won't be associated with any +// file on the filesystem or repository +func NewIndex() (*Index, error) { + var ptr *C.git_index + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if err := C.git_index_new(&ptr); err < 0 { + return nil, MakeGitError(err) + } + + return &Index{ptr: ptr}, nil +} + +// Add adds or replaces the given entry to the index, making a copy of +// the data +func (v *Index) Add(entry *IndexEntry) error { + var centry C.git_index_entry + + populateCIndexEntry(entry, ¢ry) + defer freeCIndexEntry(¢ry) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if err := C.git_index_add(v.ptr, ¢ry); err < 0 { + return MakeGitError(err) + } + + return nil +} + func (v *Index) AddByPath(path string) error { cstr := C.CString(path) defer C.free(unsafe.Pointer(cstr)) |
