Exemplo n.º 1
0
func (odb *Odb) Hash(data []byte, form ObjectType) (*Oid, error) {
	oid := new(Oid)
	cdata := unsafe.Pointer(&data[0])
	defer C.free(cdata)
	length := C.size_t(len(data))
	ecode := C.git_odb_hash(oid.git_oid, cdata, length, C.git_otype(form))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return oid, nil
}
Exemplo n.º 2
0
// 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 := unsafe.Pointer(header.Data)

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_odb_hash(oid.toC(), ptr, C.size_t(header.Len), C.git_otype(otype))
	if ret < 0 {
		return nil, MakeGitError(ret)
	}
	return oid, nil
}