Add Odb hash function.

This commit is contained in:
Claudiu-Vlad Ursache 2014-01-25 22:18:32 +01:00
parent 66e1c47619
commit 4ce2eb713b
1 changed files with 16 additions and 0 deletions

16
odb.go
View File

@ -79,6 +79,22 @@ func (v *Odb) ForEach() chan *Oid {
return ch return ch
} }
// Hash determines the object-ID (sha1) of a data buffer.
func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
oid = new(Oid)
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
ptr := (*C.char)(unsafe.Pointer(header.Data))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(ptr), C.size_t(header.Len), C.git_otype(otype));
if ret < 0 {
err = LastError()
}
return
}
// NewReadStream opens a read stream from the ODB. Reading from it will give you the // NewReadStream opens a read stream from the ODB. Reading from it will give you the
// contents of the object. // contents of the object.
func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) { func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {