From 2942e18d056d725aa847d77492a75391a670de5f Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Sun, 25 May 2014 09:06:18 +0200 Subject: Give Object and Reference an Onwer accessor This reduces the need to carry around a pointer to the repository as well as the objects. --- object.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'object.go') diff --git a/object.go b/object.go index 101d15e..9241ae2 100644 --- a/object.go +++ b/object.go @@ -22,6 +22,7 @@ type Object interface { Free() Id() *Oid Type() ObjectType + Owner() *Repository } type gitObject struct { @@ -55,6 +56,14 @@ func (o gitObject) Type() ObjectType { return ObjectType(C.git_object_type(o.ptr)) } +// Owner returns a weak reference to the repository which owns this +// object +func (o gitObject) Owner() *Repository { + return &Repository{ + ptr: C.git_object_owner(o.ptr), + } +} + func (o *gitObject) Free() { runtime.SetFinalizer(o, nil) C.git_object_free(o.ptr) -- cgit v1.2.3