MCPcopy Create free account
hub / github.com/libgit2/git2go / Hash

Method Hash

odb.go:252–272  ·  view source on GitHub ↗

Hash determines the object-ID (sha1) of a data buffer.

(data []byte, otype ObjectType)

Source from the content-addressed store, hash-verified

250
251// Hash determines the object-ID (sha1) of a data buffer.
252func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
253 oid = new(Oid)
254
255 runtime.LockOSThread()
256 defer runtime.UnlockOSThread()
257
258 var size C.size_t
259 if len(data) > 0 {
260 size = C.size_t(len(data))
261 } else {
262 data = []byte{0}
263 size = C.size_t(0)
264 }
265
266 ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_object_t(otype))
267 runtime.KeepAlive(data)
268 if ret < 0 {
269 return nil, MakeGitError(ret)
270 }
271 return oid, nil
272}
273
274// NewReadStream opens a read stream from the ODB. Reading from it will give you the
275// contents of the object.

Callers 1

TestOdbHashFunction · 0.80

Calls 2

MakeGitErrorFunction · 0.85
toCMethod · 0.45

Tested by 1

TestOdbHashFunction · 0.64