summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-05-25 18:12:50 +0200
committerCarlos Martín Nieto <[email protected]>2014-05-25 18:12:50 +0200
commitf953d4e5c7c676cd3b3ee797fedce8823b5c930c (patch)
tree0d418dc29a682e93048468823fff8f936d4203e7 /index.go
parent2942e18d056d725aa847d77492a75391a670de5f (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.go33
1 files changed, 33 insertions, 0 deletions
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, &centry)
+ defer freeCIndexEntry(&centry)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if err := C.git_index_add(v.ptr, &centry); err < 0 {
+ return MakeGitError(err)
+ }
+
+ return nil
+}
+
func (v *Index) AddByPath(path string) error {
cstr := C.CString(path)
defer C.free(unsafe.Pointer(cstr))