Skip to content

Commit 7f685a6

Browse files
committed
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.
1 parent 2cff3f2 commit 7f685a6

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

blob.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ type Blob struct {
2020
cast_ptr *C.git_blob
2121
}
2222

23+
func (b *Blob) AsObject() *Object {
24+
return &b.Object
25+
}
26+
2327
func (v *Blob) Size() int64 {
2428
ret := int64(C.git_blob_rawsize(v.cast_ptr))
2529
runtime.KeepAlive(v)

commit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type Commit struct {
1818
cast_ptr *C.git_commit
1919
}
2020

21+
func (c *Commit) AsObject() *Object {
22+
return &c.Object
23+
}
24+
2125
func (c *Commit) Message() string {
2226
ret := C.GoString(C.git_commit_message(c.cast_ptr))
2327
runtime.KeepAlive(c)

object.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ type Object struct {
2626
repo *Repository
2727
}
2828

29+
// Objecter lets us accept any kind of Git object in functions.
30+
type Objecter interface {
31+
AsObject() *Object
32+
}
33+
2934
func (t ObjectType) String() string {
3035
switch t {
3136
case ObjectAny:

tag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type Tag struct {
1717
cast_ptr *C.git_tag
1818
}
1919

20+
func (t *Tag) AsObject() *Object {
21+
return &t.Object
22+
}
23+
2024
func (t Tag) Message() string {
2125
ret := C.GoString(C.git_tag_message(t.cast_ptr))
2226
runtime.KeepAlive(t)

tree.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type Tree struct {
2727
cast_ptr *C.git_tree
2828
}
2929

30+
func (t *Tree) AsObject() *Object {
31+
return &t.Object
32+
}
33+
3034
type TreeEntry struct {
3135
Name string
3236
Id *Oid

0 commit comments

Comments
 (0)