Example #1
0
func NewSignature(name, email string, when time.Time) (*Signature, error) {
	sig := new(Signature)
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	cemail := C.CString(email)
	defer C.free(unsafe.Pointer(cemail))
	ctime := C.git_time_t(when.Unix())
	_, offset := when.Zone()
	coffset := C.int(offset / 60)
	ecode := C.git_signature_new(&sig.git_signature, cname, cemail, ctime, coffset)
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return sig, nil
}
Example #2
0
func (sig *Signature) toC() *C.git_signature {
	var out *C.git_signature

	name := C.CString(sig.Name)
	defer C.free(unsafe.Pointer(name))

	email := C.CString(sig.Email)
	defer C.free(unsafe.Pointer(email))

	ret := C.git_signature_new(&out, name, email, C.git_time_t(sig.When.Unix()), C.int(sig.Offset()))
	if ret < 0 {
		return nil
	}

	return out
}
Example #3
0
func (sig *Signature) toC() (*C.git_signature, error) {
	if sig == nil {
		return nil, nil
	}

	var out *C.git_signature

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	name := C.CString(sig.Name)
	defer C.free(unsafe.Pointer(name))

	email := C.CString(sig.Email)
	defer C.free(unsafe.Pointer(email))

	ret := C.git_signature_new(&out, name, email, C.git_time_t(sig.When.Unix()), C.int(sig.Offset()))
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return out, nil
}