diff options
| author | lhchavez <[email protected]> | 2020-02-23 15:08:45 +0000 |
|---|---|---|
| committer | lhchavez <[email protected]> | 2020-02-23 15:08:45 +0000 |
| commit | 3c88bd9f1aebc53ea9d77937829f8c155aa834c3 (patch) | |
| tree | 8556d00fb42f2fcab5ba748e49e21e1141b9d604 /index.go | |
| parent | c75e0221d70bc471917aa3de34ca1ead1a747987 (diff) | |
| parent | 21d618136f415486d95965e75af80c0e6688a0d5 (diff) | |
Merge remote-tracking branch 'upstream/master' into cherrypick-commit
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 40 |
1 files changed, 39 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) } @@ -145,6 +147,20 @@ func (v *Index) Path() string { return ret } +// Clear clears the index object in memory; changes must be explicitly +// written to disk for them to take effect persistently +func (v *Index) Clear() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + err := C.git_index_clear(v.ptr) + runtime.KeepAlive(v) + if err < 0 { + return MakeGitError(err) + } + return nil +} + // Add adds or replaces the given entry to the index, making a copy of // the data func (v *Index) Add(entry *IndexEntry) error { @@ -181,6 +197,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_from_buffer(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)) |
