| 430 | } |
| 431 | |
| 432 | func (v *Repository) CreateCommit( |
| 433 | refname string, author, committer *Signature, |
| 434 | message string, tree *Tree, parents ...*Commit) (*Oid, error) { |
| 435 | |
| 436 | oid := new(Oid) |
| 437 | |
| 438 | var cref *C.char |
| 439 | if refname == "" { |
| 440 | cref = nil |
| 441 | } else { |
| 442 | cref = C.CString(refname) |
| 443 | defer C.free(unsafe.Pointer(cref)) |
| 444 | } |
| 445 | |
| 446 | cmsg := C.CString(message) |
| 447 | defer C.free(unsafe.Pointer(cmsg)) |
| 448 | |
| 449 | var cparents []*C.git_commit = nil |
| 450 | var parentsarg **C.git_commit = nil |
| 451 | |
| 452 | nparents := len(parents) |
| 453 | if nparents > 0 { |
| 454 | cparents = make([]*C.git_commit, nparents) |
| 455 | for i, v := range parents { |
| 456 | cparents[i] = v.cast_ptr |
| 457 | } |
| 458 | parentsarg = &cparents[0] |
| 459 | } |
| 460 | |
| 461 | authorSig, err := author.toC() |
| 462 | if err != nil { |
| 463 | return nil, err |
| 464 | } |
| 465 | defer C.git_signature_free(authorSig) |
| 466 | |
| 467 | committerSig, err := committer.toC() |
| 468 | if err != nil { |
| 469 | return nil, err |
| 470 | } |
| 471 | defer C.git_signature_free(committerSig) |
| 472 | |
| 473 | runtime.LockOSThread() |
| 474 | defer runtime.UnlockOSThread() |
| 475 | |
| 476 | ret := C.git_commit_create( |
| 477 | oid.toC(), v.ptr, cref, |
| 478 | authorSig, committerSig, |
| 479 | nil, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg) |
| 480 | |
| 481 | runtime.KeepAlive(v) |
| 482 | runtime.KeepAlive(oid) |
| 483 | runtime.KeepAlive(parents) |
| 484 | if ret < 0 { |
| 485 | return nil, MakeGitError(ret) |
| 486 | } |
| 487 | |
| 488 | return oid, nil |
| 489 | } |