diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-02-23 16:02:35 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-02-23 16:02:35 +0100 |
| commit | 0a1052b0e08d6a2174734d0c92ae192b726b2990 (patch) | |
| tree | 966ea0fb9bc4088c541850ee8a98339eca2e402a /odb.go | |
| parent | af80cc73ad16550f9b79e1b551b49f94bce5809a (diff) | |
| parent | bf209ca2ba293116bdd3062ba9ff5ac071f9ddd5 (diff) | |
Merge pull request #52 from ursachec/master
Support for git_odb_hash.
Diffstat (limited to 'odb.go')
| -rw-r--r-- | odb.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -79,6 +79,22 @@ func (v *Odb) ForEach() chan *Oid { 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 := 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 { + err = LastError() + } + return +} + // NewReadStream opens a read stream from the ODB. Reading from it will give you the // contents of the object. func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) { |
