-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature.go
52 lines (46 loc) · 1.19 KB
/
signature.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package git2
// #cgo pkg-config: libgit2
// #include <git2.h>
import "C"
import (
"time"
"unsafe"
)
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
}
func SignatureNow(name, email string) (*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))
ecode := C.git_signature_now(&sig.git_signature, cname, cemail)
if ecode != git_SUCCESS {
return nil, gitError()
}
return sig, nil
}
type Signature struct {
git_signature *C.git_signature
}
func (sig *Signature) Duplicate() *Signature {
newSig := new(Signature)
newSig.git_signature = C.git_signature_dup(sig.git_signature)
return newSig
}
func (sig *Signature) Free() {
C.git_signature_free(sig.git_signature)
}