From f953d4e5c7c676cd3b3ee797fedce8823b5c930c Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Sun, 25 May 2014 18:12:50 +0200 Subject: Index: add functions to handle the data structure Index is not just the index file --- index.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'index.go') diff --git a/index.go b/index.go index f20dc31..f8ce6b3 100644 --- a/index.go +++ b/index.go @@ -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)) -- cgit v1.2.3