func (repo *Repository) CreateCommit(ref string, author, committer *Signature, encoding, message string, tree *Tree, parents ...*Commit) (*Oid, error) { oid := new(Oid) oid.git_oid = new(C.git_oid) cref := C.CString(ref) defer C.free(unsafe.Pointer(cref)) cencoding := C.CString(encoding) defer C.free(unsafe.Pointer(cencoding)) cmessage := C.CString(message) defer C.free(unsafe.Pointer(cmessage)) parentCount := len(parents) cparentCount := C.int(parentCount) var cparentsSlice []*C.git_commit var cparents **C.git_commit if parentCount > 0 { cparentsSlice = make([]*C.git_commit, parentCount) for i := 0; i < parentCount; i++ { cparentsSlice[i] = parents[i].git_commit } cparents = &cparentsSlice[0] } ecode := C.git_commit_create(oid.git_oid, repo.git_repository, cref, author.git_signature, committer.git_signature, cencoding, cmessage, tree.git_tree, cparentCount, cparents) if ecode != git_SUCCESS { return nil, gitError() } return oid, nil }
func (v *Repository) CreateCommit( refname string, author, committer *Signature, message string, tree *Tree, parents ...*Commit) (*Oid, error) { oid := new(Oid) var cref *C.char if refname == "" { cref = nil } else { cref = C.CString(refname) defer C.free(unsafe.Pointer(cref)) } cmsg := C.CString(message) defer C.free(unsafe.Pointer(cmsg)) var cparents []*C.git_commit = nil var parentsarg **C.git_commit = nil nparents := len(parents) if nparents > 0 { cparents = make([]*C.git_commit, nparents) for i, v := range parents { cparents[i] = v.cast_ptr } parentsarg = &cparents[0] } authorSig, err := author.toC() if err != nil { return nil, err } defer C.git_signature_free(authorSig) committerSig, err := committer.toC() if err != nil { return nil, err } defer C.git_signature_free(committerSig) runtime.LockOSThread() defer runtime.UnlockOSThread() ret := C.git_commit_create( oid.toC(), v.ptr, cref, authorSig, committerSig, nil, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg) if ret < 0 { return nil, MakeGitError(ret) } return oid, nil }
func (v *Repository) CreateCommit( refname string, author, committer *Signature, message string, tree *Tree, parents ...*Commit) (*Oid, error) { oid := new(Oid) cref := C.CString(refname) defer C.free(unsafe.Pointer(cref)) cmsg := C.CString(message) defer C.free(unsafe.Pointer(cmsg)) var cparents []*C.git_commit = nil var parentsarg **C.git_commit = nil nparents := len(parents) if nparents > 0 { cparents = make([]*C.git_commit, nparents) for i, v := range parents { cparents[i] = v.ptr } parentsarg = &cparents[0] } authorSig := author.toC() defer C.git_signature_free(authorSig) committerSig := committer.toC() defer C.git_signature_free(committerSig) ret := C.git_commit_create( oid.toC(), v.ptr, cref, authorSig, committerSig, nil, cmsg, tree.ptr, C.int(nparents), parentsarg) if ret < 0 { return nil, LastError() } return oid, nil }
func (r *GitRepository) Commit(name, email string) error { var ret C.int var index *C.git_index ret = C.git_repository_index(&index, r.ptr) if ret < 0 { return GitErrorLast() } defer C.git_index_free(index) treeOid := new(C.git_oid) ret = C.git_index_write_tree(treeOid, index) if ret < 0 { return GitErrorLast() } tree := new(C.git_tree) ret = C.git_tree_lookup(&tree, r.ptr, treeOid) if ret < 0 { return GitErrorLast() } defer C.git_tree_free(tree) signature := new(C.git_signature) cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) cEmail := C.CString(email) defer C.free(unsafe.Pointer(cEmail)) ret = C.git_signature_now(&signature, cName, cEmail) if ret < 0 { return GitErrorLast() } defer C.git_signature_free(signature) headOid := new(C.git_oid) cHead := C.CString("HEAD") defer C.free(unsafe.Pointer(cHead)) ret = C.git_reference_name_to_id(headOid, r.ptr, cHead) commitOid := new(C.git_oid) cMessage := C.CString("") defer C.free(unsafe.Pointer(cMessage)) if ret == 0 { head := new(C.git_commit) ret = C.git_commit_lookup(&head, r.ptr, headOid) if ret < 0 { return GitErrorLast() } defer C.git_commit_free(head) parents := make([]*C.git_commit, 1) parents[0] = head ret = C.git_commit_create( commitOid, r.ptr, cHead, signature, signature, nil, cMessage, tree, 1, &parents[0], ) } else { ret = C.git_commit_create( commitOid, r.ptr, cHead, signature, signature, nil, cMessage, tree, 0, nil, ) } if ret < 0 { return GitErrorLast() } ret = C.git_index_write(index) if ret < 0 { return GitErrorLast() } return nil }