2013-03-05 13:53:04 -06:00
|
|
|
package git
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <git2.h>
|
|
|
|
|
|
|
|
extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr);
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2013-09-18 02:23:47 -05:00
|
|
|
"runtime"
|
2013-03-05 13:53:04 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// Commit
|
|
|
|
type Commit struct {
|
2013-04-17 17:54:46 -05:00
|
|
|
gitObject
|
2014-04-01 05:13:37 -05:00
|
|
|
cast_ptr *C.git_commit
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 17:54:46 -05:00
|
|
|
func (c Commit) Message() string {
|
2014-04-01 05:13:37 -05:00
|
|
|
return C.GoString(C.git_commit_message(c.cast_ptr))
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2015-03-04 17:35:35 -06:00
|
|
|
func (c Commit) Summary() string {
|
|
|
|
return C.GoString(C.git_commit_summary(c.cast_ptr))
|
|
|
|
}
|
|
|
|
|
2013-04-17 17:54:46 -05:00
|
|
|
func (c Commit) Tree() (*Tree, error) {
|
2014-04-01 05:13:37 -05:00
|
|
|
var ptr *C.git_tree
|
2013-03-05 13:53:04 -06:00
|
|
|
|
2013-09-18 02:23:47 -05:00
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
2014-04-01 05:13:37 -05:00
|
|
|
err := C.git_commit_tree(&ptr, c.cast_ptr)
|
2013-03-05 13:53:04 -06:00
|
|
|
if err < 0 {
|
2013-07-07 09:43:44 -05:00
|
|
|
return nil, MakeGitError(err)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
2013-03-05 18:43:48 -06:00
|
|
|
|
2014-05-26 02:28:07 -05:00
|
|
|
return allocObject((*C.git_object)(ptr), c.repo).(*Tree), nil
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 17:54:46 -05:00
|
|
|
func (c Commit) TreeId() *Oid {
|
2014-04-01 05:13:37 -05:00
|
|
|
return newOidFromC(C.git_commit_tree_id(c.cast_ptr))
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 17:54:46 -05:00
|
|
|
func (c Commit) Author() *Signature {
|
2014-04-01 05:13:37 -05:00
|
|
|
cast_ptr := C.git_commit_author(c.cast_ptr)
|
|
|
|
return newSignatureFromC(cast_ptr)
|
2013-03-05 13:53:04 -06:00
|
|
|
}
|
|
|
|
|
2013-04-17 17:54:46 -05:00
|
|
|
func (c Commit) Committer() *Signature {
|
2014-04-01 05:13:37 -05:00
|
|
|
cast_ptr := C.git_commit_committer(c.cast_ptr)
|
|
|
|
return newSignatureFromC(cast_ptr)
|
2013-03-05 16:18:07 -06:00
|
|
|
}
|
|
|
|
|
2013-05-21 16:18:02 -05:00
|
|
|
func (c *Commit) Parent(n uint) *Commit {
|
2014-04-01 05:13:37 -05:00
|
|
|
var cobj *C.git_commit
|
|
|
|
ret := C.git_commit_parent(&cobj, c.cast_ptr, C.uint(n))
|
2013-05-21 16:18:02 -05:00
|
|
|
if ret != 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2013-11-14 07:24:43 -06:00
|
|
|
|
2014-05-26 02:28:07 -05:00
|
|
|
return allocObject((*C.git_object)(cobj), c.repo).(*Commit)
|
2013-05-21 16:18:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Commit) ParentId(n uint) *Oid {
|
2014-04-01 05:13:37 -05:00
|
|
|
return newOidFromC(C.git_commit_parent_id(c.cast_ptr, C.uint(n)))
|
2013-05-21 16:18:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Commit) ParentCount() uint {
|
2014-04-01 05:13:37 -05:00
|
|
|
return uint(C.git_commit_parentcount(c.cast_ptr))
|
2013-05-21 16:18:02 -05:00
|
|
|
}
|