summaryrefslogtreecommitdiff
path: root/odb.go
diff options
context:
space:
mode:
authorAidan Nulman <[email protected]>2014-02-24 03:05:44 -0500
committerAidan Nulman <[email protected]>2014-02-24 03:05:44 -0500
commit2656a72e823e16451480b7858213f6e3cb8bb2fd (patch)
treee31656bc81965c4d18864d8305f2f6ff65fd627a /odb.go
parentdecaf064f9ace275789657343d5123ee5290ea31 (diff)
parentc6d1bde37cc7f3bd213fc182fd9f60a7cd685419 (diff)
Merge branch 'master' into custom_odb
Conflicts: git.go reference.go repository.go submodule.go
Diffstat (limited to 'odb.go')
-rw-r--r--odb.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/odb.go b/odb.go
index fc8fbd4..4a5187c 100644
--- a/odb.go
+++ b/odb.go
@@ -110,6 +110,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) {