From d190d8a6b3717402744902d060be57195f27d604 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 16 Apr 2013 23:04:35 +0200 Subject: Take 2 on polymorphism --- commit.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'commit.go') diff --git a/commit.go b/commit.go index d31f684..b1ca6c4 100644 --- a/commit.go +++ b/commit.go @@ -19,8 +19,17 @@ type Commit struct { ptr *C.git_commit } -func (c *Commit) Id() *Oid { - return newOidFromC(C.git_commit_id(c.ptr)) +func (o *Commit) Id() *Oid { + return newOidFromC(C.git_commit_id(o.ptr)) +} + +func (o *Commit) Type() ObjectType { + return OBJ_COMMIT +} + +func (o *Commit) Free() { + runtime.SetFinalizer(o, nil) + C.git_commit_free(o.ptr) } func (c *Commit) Message() string { @@ -28,15 +37,14 @@ func (c *Commit) Message() string { } func (c *Commit) Tree() (*Tree, error) { - tree := new(Tree) + 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 { -- cgit v1.2.3