diff options
| author | Vicent Marti <[email protected]> | 2013-04-18 00:54:46 +0200 |
|---|---|---|
| committer | Vicent Marti <[email protected]> | 2013-04-18 00:54:46 +0200 |
| commit | 2bf17ba2f18ad3ae3068568e5754046544b159b7 (patch) | |
| tree | b1cf90f9969d54ea41e06d9930e23004c92c9f99 /object.go | |
| parent | 7292cafac2d2c4462f3bc0b850e702d6d87f629e (diff) | |
Ok, now with shared base object
Diffstat (limited to 'object.go')
| -rw-r--r-- | object.go | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -25,25 +25,41 @@ type Object interface { Type() ObjectType } +type gitObject struct { + ptr *C.git_object +} + +func (o gitObject) Id() *Oid { + return newOidFromC(C.git_commit_id(o.ptr)) +} + +func (o gitObject) Type() ObjectType { + return ObjectType(C.git_object_type(o.ptr)) +} + +func (o gitObject) Free() { + runtime.SetFinalizer(o, nil) + C.git_commit_free(o.ptr) +} + func allocObject(cobj *C.git_object) Object { - var object Object switch ObjectType(C.git_object_type(cobj)) { case OBJ_COMMIT: - object = &Commit{cobj} - runtime.SetFinalizer(object, (*Commit).Free) + commit := &Commit{gitObject{cobj}} + runtime.SetFinalizer(commit, (*Commit).Free) + return commit case OBJ_TREE: - object = &Tree{cobj} - runtime.SetFinalizer(object, (*Tree).Free) + tree := &Tree{gitObject{cobj}} + runtime.SetFinalizer(tree, (*Tree).Free) + return tree case OBJ_BLOB: - object = &Blob{cobj} - runtime.SetFinalizer(object, (*Blob).Free) - - default: - return nil + blob := &Blob{gitObject{cobj}} + runtime.SetFinalizer(blob, (*Blob).Free) + return blob } - return object + return nil } |
