diff options
| author | Carlos Martín Nieto <[email protected]> | 2015-05-19 14:56:01 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2015-05-19 14:56:01 +0200 |
| commit | d7a0495000e35d06993605a9a31a5f9823292f8a (patch) | |
| tree | 3c0098d3ede28bb1488b786482b41c26d736e54e /index.go | |
| parent | a8ad0d204052d8bd9c4d0093cce62c54afa67188 (diff) | |
Index: Add OpenIndex
This lets you persist an index at an arbitrary location.
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -96,6 +96,24 @@ func NewIndex() (*Index, error) { return &Index{ptr: ptr}, nil } +// OpenIndex creates a new index at the given path. If the file does +// not exist it will be created when Write() is called. +func OpenIndex(path string) (*Index, error) { + var ptr *C.git_index + + var cpath = C.CString(path) + defer C.free(unsafe.Pointer(cpath)) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if err := C.git_index_open(&ptr, cpath); 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 { |
