MCPcopy Create free account
hub / github.com/libgit2/git2go / CreateBlobFromBuffer

Method CreateBlobFromBuffer

blob.go:49–77  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

47}
48
49func (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
79func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, error) {
80 var chintPath *C.char = nil

Callers 3

commitSomethingFunction · 0.80
TestCreateBlobFromBufferFunction · 0.80

Calls 2

MakeGitErrorFunction · 0.85
newOidFromCFunction · 0.85

Tested by 3

commitSomethingFunction · 0.64
TestCreateBlobFromBufferFunction · 0.64