@@ -90,7 +90,9 @@ func populateCIndexEntry(source *IndexEntry, dest *C.git_index_entry) {
9090 dest .uid = C .uint32_t (source .Uid )
9191 dest .gid = C .uint32_t (source .Gid )
9292 dest .file_size = C .uint32_t (source .Size )
93- dest .id = * source .Id .toC ()
93+ if source .Id != nil {
94+ dest .id = * source .Id .toC ()
95+ }
9496 dest .path = C .CString (source .Path )
9597}
9698
@@ -195,6 +197,28 @@ func (v *Index) AddByPath(path string) error {
195197 return nil
196198}
197199
200+ // AddFromBuffer adds or replaces an index entry from a buffer in memory
201+ func (v * Index ) AddFromBuffer (entry * IndexEntry , buffer []byte ) error {
202+ var centry C.git_index_entry
203+
204+ populateCIndexEntry (entry , & centry )
205+ defer freeCIndexEntry (& centry )
206+
207+ var cbuffer unsafe.Pointer
208+ if len (buffer ) > 0 {
209+ cbuffer = unsafe .Pointer (& buffer [0 ])
210+ }
211+
212+ runtime .LockOSThread ()
213+ defer runtime .UnlockOSThread ()
214+
215+ if err := C .git_index_add_frombuffer (v .ptr , & centry , cbuffer , C .size_t (len (buffer ))); err < 0 {
216+ return MakeGitError (err )
217+ }
218+
219+ return nil
220+ }
221+
198222func (v * Index ) AddAll (pathspecs []string , flags IndexAddOpts , callback IndexMatchedPathCallback ) error {
199223 cpathspecs := C.git_strarray {}
200224 cpathspecs .count = C .size_t (len (pathspecs ))
0 commit comments