| 47 | } |
| 48 | |
| 49 | func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) { |
| 50 | runtime.LockOSThread() |
| 51 | defer runtime.UnlockOSThread() |
| 52 | |
| 53 | var id C.git_oid |
| 54 | var size C.size_t |
| 55 | |
| 56 | // Go 1.6 added some increased checking of passing pointer to |
| 57 | // C, but its check depends on its expectations of what we |
| 58 | // pass to the C function, so unless we take the address of |
| 59 | // its contents at the call site itself, it can fail when |
| 60 | // 'data' is a slice of a slice. |
| 61 | // |
| 62 | // When we're given an empty slice, create a dummy one where 0 |
| 63 | // isn't out of bounds. |
| 64 | if len(data) > 0 { |
| 65 | size = C.size_t(len(data)) |
| 66 | } else { |
| 67 | data = []byte{0} |
| 68 | size = C.size_t(0) |
| 69 | } |
| 70 | |
| 71 | ecode := C.git_blob_create_from_buffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size) |
| 72 | runtime.KeepAlive(repo) |
| 73 | if ecode < 0 { |
| 74 | return nil, MakeGitError(ecode) |
| 75 | } |
| 76 | return newOidFromC(&id), nil |
| 77 | } |
| 78 | |
| 79 | func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, error) { |
| 80 | var chintPath *C.char = nil |