Add Objecer interface

We do want to be able to accept generic objects in functions. Add this interface
so we can accept that instead of specific object types.
This commit is contained in:
Carlos Martín Nieto 2017-07-08 22:53:50 +02:00
parent 2cff3f2ef4
commit 7f685a6ee6
5 changed files with 21 additions and 0 deletions

View File

@ -20,6 +20,10 @@ type Blob struct {
cast_ptr *C.git_blob cast_ptr *C.git_blob
} }
func (b *Blob) AsObject() *Object {
return &b.Object
}
func (v *Blob) Size() int64 { func (v *Blob) Size() int64 {
ret := int64(C.git_blob_rawsize(v.cast_ptr)) ret := int64(C.git_blob_rawsize(v.cast_ptr))
runtime.KeepAlive(v) runtime.KeepAlive(v)

View File

@ -18,6 +18,10 @@ type Commit struct {
cast_ptr *C.git_commit cast_ptr *C.git_commit
} }
func (c *Commit) AsObject() *Object {
return &c.Object
}
func (c *Commit) Message() string { func (c *Commit) Message() string {
ret := C.GoString(C.git_commit_message(c.cast_ptr)) ret := C.GoString(C.git_commit_message(c.cast_ptr))
runtime.KeepAlive(c) runtime.KeepAlive(c)

View File

@ -26,6 +26,11 @@ type Object struct {
repo *Repository repo *Repository
} }
// Objecter lets us accept any kind of Git object in functions.
type Objecter interface {
AsObject() *Object
}
func (t ObjectType) String() string { func (t ObjectType) String() string {
switch t { switch t {
case ObjectAny: case ObjectAny:

4
tag.go
View File

@ -17,6 +17,10 @@ type Tag struct {
cast_ptr *C.git_tag cast_ptr *C.git_tag
} }
func (t *Tag) AsObject() *Object {
return &t.Object
}
func (t Tag) Message() string { func (t Tag) Message() string {
ret := C.GoString(C.git_tag_message(t.cast_ptr)) ret := C.GoString(C.git_tag_message(t.cast_ptr))
runtime.KeepAlive(t) runtime.KeepAlive(t)

View File

@ -27,6 +27,10 @@ type Tree struct {
cast_ptr *C.git_tree cast_ptr *C.git_tree
} }
func (t *Tree) AsObject() *Object {
return &t.Object
}
type TreeEntry struct { type TreeEntry struct {
Name string Name string
Id *Oid Id *Oid