Exemple #1
0
func (os *OidShorten) Add(oid string) (int, error) {
	coid := C.CString(oid)
	defer C.free(unsafe.Pointer(coid))
	num := C.git_oid_shorten_add(os.git_oid_shorten, coid)
	if num < 0 {
		return 0, gitError()
	}
	return int(num), nil
}
Exemple #2
0
func ShortenOids(ids []*Oid, minlen int) (int, error) {
	shorten := C.git_oid_shorten_new(C.size_t(minlen))
	if shorten == nil {
		panic("Out of memory")
	}
	defer C.git_oid_shorten_free(shorten)

	var ret C.int
	for _, id := range ids {
		buf := make([]byte, 41)
		C.git_oid_fmt((*C.char)(unsafe.Pointer(&buf[0])), id.toC())
		buf[40] = 0
		ret = C.git_oid_shorten_add(shorten, (*C.char)(unsafe.Pointer(&buf[0])))
		if ret < 0 {
			return int(ret), LastError()
		}
	}
	return int(ret), nil
}