Add a couple of missing methods around Blob #7

Merged
carlosmn merged 1 commits from blob into master 2013-03-06 17:01:43 -06:00
2 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,10 @@ func (v *Blob) Free() {
C.git_object_free(v.ptr)
}
func (v *Blob) Size() int64 {
return int64(C.git_blob_rawsize(v.ptr))
}
func (v *Blob) Contents() []byte {
size := C.int(C.git_blob_rawsize(v.ptr))
buffer := unsafe.Pointer(C.git_blob_rawcontent(v.ptr))

View File

@ -92,6 +92,17 @@ func (v *Repository) LookupCommit(o *Oid) (*Commit, error) {
return commit, nil
}
func (v *Repository) LookupBlob(o *Oid) (*Blob, error) {
blob := new(Blob)
ecode := C.git_blob_lookup(&blob.ptr, v.ptr, o.toC())
if ecode < 0 {
return nil, LastError()
}
runtime.SetFinalizer(blob, (*Blob).Free)
return blob, nil
}
func (v *Repository) Walk() (*RevWalk, error) {
walk := new(RevWalk)
ecode := C.git_revwalk_new(&walk.ptr, v.ptr)