diff options
| author | Vadzim Ramanenka <[email protected]> | 2017-07-17 13:12:43 +0300 |
|---|---|---|
| committer | Vadzim Ramanenka <[email protected]> | 2017-07-17 17:05:03 +0300 |
| commit | 79fe156d307a9c7b294aa92c741dc0c2759a1894 (patch) | |
| tree | d1d19c118114f858f681e83e80f85b1a21336a67 /index.go | |
| parent | 7969aefd42abf3d3d93397760e54c872493e0972 (diff) | |
Add binding for `git_index_add_frombuffer`
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -90,7 +90,9 @@ func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) { dest.uid = C.uint32_t(source.Uid) dest.gid = C.uint32_t(source.Gid) dest.file_size = C.uint32_t(source.Size) - dest.id = *source.Id.toC() + if source.Id != nil { + dest.id = *source.Id.toC() + } dest.path = C.CString(source.Path) } @@ -181,6 +183,28 @@ func (v *Index) AddByPath(path string) error { return nil } +// AddFromBuffer adds or replaces an index entry from a buffer in memory +func (v *Index) AddFromBuffer(entry *IndexEntry, buffer []byte) error { + var centry C.git_index_entry + + populateCIndexEntry(entry, ¢ry) + defer freeCIndexEntry(¢ry) + + var cbuffer unsafe.Pointer + if len(buffer) > 0 { + cbuffer = unsafe.Pointer(&buffer[0]) + } + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if err := C.git_index_add_frombuffer(v.ptr, ¢ry, cbuffer, C.size_t(len(buffer))); err < 0 { + return MakeGitError(err) + } + + return nil +} + func (v *Index) AddAll(pathspecs []string, flags IndexAddOpts, callback IndexMatchedPathCallback) error { cpathspecs := C.git_strarray{} cpathspecs.count = C.size_t(len(pathspecs)) |
