summaryrefslogtreecommitdiff
path: root/commit.go
diff options
context:
space:
mode:
authorVicent Martí <[email protected]>2013-06-13 10:15:36 -0700
committerVicent Martí <[email protected]>2013-06-13 10:15:36 -0700
commit62f65d071d0671fb53aaca54a2d59a636267c2b0 (patch)
treee03dd9af8fb0e7287abfc0597c1a325013ee0073 /commit.go
parent01d1a5c5d5fede6f054e50a1154ff747e3879cf8 (diff)
parent5766c4accf913bb4a98189177261e1db939397e2 (diff)
Merge pull request #13 from libgit2/polymorphism-take-2
My take on polymorphism
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go24
1 files changed, 9 insertions, 15 deletions
diff --git a/commit.go b/commit.go
index 06d1a22..cacaa33 100644
--- a/commit.go
+++ b/commit.go
@@ -9,46 +9,40 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr);
import "C"
import (
- "runtime"
"unsafe"
"time"
)
// Commit
type Commit struct {
- ptr *C.git_commit
+ gitObject
}
-func (c *Commit) Id() *Oid {
- return newOidFromC(C.git_commit_id(c.ptr))
-}
-
-func (c *Commit) Message() string {
+func (c Commit) Message() string {
return C.GoString(C.git_commit_message(c.ptr))
}
-func (c *Commit) Tree() (*Tree, error) {
- tree := new(Tree)
+func (c Commit) Tree() (*Tree, error) {
+ var ptr *C.git_object
- err := C.git_commit_tree(&tree.ptr, c.ptr)
+ err := C.git_commit_tree(&ptr, c.ptr)
if err < 0 {
return nil, LastError()
}
- runtime.SetFinalizer(tree, (*Tree).Free)
- return tree, nil
+ return allocObject(ptr).(*Tree), nil
}
-func (c *Commit) TreeId() *Oid {
+func (c Commit) TreeId() *Oid {
return newOidFromC(C.git_commit_tree_id(c.ptr))
}
-func (c *Commit) Author() *Signature {
+func (c Commit) Author() *Signature {
ptr := C.git_commit_author(c.ptr)
return newSignatureFromC(ptr)
}
-func (c *Commit) Committer() *Signature {
+func (c Commit) Committer() *Signature {
ptr := C.git_commit_committer(c.ptr)
return newSignatureFromC(ptr)
}