diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-05-25 18:12:50 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-05-25 18:12:50 +0200 |
| commit | f953d4e5c7c676cd3b3ee797fedce8823b5c930c (patch) | |
| tree | 0d418dc29a682e93048468823fff8f936d4203e7 /index.go | |
| parent | 2942e18d056d725aa847d77492a75391a670de5f (diff) | |
Index: add functions to handle the data structure
Index is not just the index file
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)) |
