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

Method CreateCommitBuffer

repository.go:525–585  ·  view source on GitHub ↗

CreateCommitBuffer creates a commit and write it into a buffer.

(
	author, committer *Signature,
	messageEncoding MessageEncoding,
	message string,
	tree *Tree,
	parents ...*Commit,
)

Source from the content-addressed store, hash-verified

523
524// CreateCommitBuffer creates a commit and write it into a buffer.
525func (v *Repository) CreateCommitBuffer(
526 author, committer *Signature,
527 messageEncoding MessageEncoding,
528 message string,
529 tree *Tree,
530 parents ...*Commit,
531) ([]byte, error) {
532 cmsg := C.CString(message)
533 defer C.free(unsafe.Pointer(cmsg))
534 var cencoding *C.char
535 // Since the UTF-8 encoding is the default, pass in nil whenever UTF-8 is
536 // provided. That will cause the commit to not have an explicit header for
537 // it.
538 if messageEncoding != MessageEncodingUTF8 && messageEncoding != MessageEncoding("") {
539 cencoding = C.CString(string(messageEncoding))
540 defer C.free(unsafe.Pointer(cencoding))
541 }
542
543 var cparents []*C.git_commit = nil
544 var parentsarg **C.git_commit = nil
545
546 nparents := len(parents)
547 if nparents > 0 {
548 cparents = make([]*C.git_commit, nparents)
549 for i, v := range parents {
550 cparents[i] = v.cast_ptr
551 }
552 parentsarg = &cparents[0]
553 }
554
555 authorSig, err := author.toC()
556 if err != nil {
557 return nil, err
558 }
559 defer C.git_signature_free(authorSig)
560
561 committerSig, err := committer.toC()
562 if err != nil {
563 return nil, err
564 }
565 defer C.git_signature_free(committerSig)
566
567 runtime.LockOSThread()
568 defer runtime.UnlockOSThread()
569
570 var buf C.git_buf
571 defer C.git_buf_dispose(&buf)
572 ret := C.git_commit_create_buffer(
573 &buf, v.ptr,
574 authorSig, committerSig,
575 cencoding, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
576
577 runtime.KeepAlive(v)
578 runtime.KeepAlive(buf)
579 runtime.KeepAlive(parents)
580 if ret < 0 {
581 return nil, MakeGitError(ret)
582 }

Callers 2

commitCreateCallbackFunction · 0.80
TestCreateCommitBufferFunction · 0.80

Calls 4

MessageEncodingTypeAlias · 0.85
MakeGitErrorFunction · 0.85
freeMethod · 0.80
toCMethod · 0.45

Tested by 1

TestCreateCommitBufferFunction · 0.64