summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu-Vlad Ursache <[email protected]>2014-01-25 22:18:32 +0100
committerClaudiu-Vlad Ursache <[email protected]>2014-01-25 22:18:32 +0100
commit4ce2eb713bda2cb361f6d2b58502bea758ca980e (patch)
treecd319face9e5fcbc4ffcca1e8c9d4a335beb1001
parent66e1c476199ebcd3e304659992233132c5a52c6c (diff)
Add Odb hash function.
-rw-r--r--odb.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/odb.go b/odb.go
index 638ef74..6d18ce9 100644
--- a/odb.go
+++ b/odb.go
@@ -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 := (*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
// contents of the object.
func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {