This repository was archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit2go.go
More file actions
73 lines (60 loc) · 1.31 KB
/
git2go.go
File metadata and controls
73 lines (60 loc) · 1.31 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gitdb
/*
#include <git2.h>
#include <git2/sys/refs.h>
*/
import "C"
import (
"runtime"
"time"
"unsafe"
git "gopkg.in/libgit2/git2go.v27"
)
func newOidFromC(coid *C.git_oid) *git.Oid {
if coid == nil {
return nil
}
return git.NewOidFromBytes(C.GoBytes(unsafe.Pointer(coid), 20))
}
type reference struct {
ptr *C.git_reference
}
// weak reference, only for view
func newReferenceFromC(ptr *C.git_reference) *reference {
return &reference{
ptr: ptr,
}
}
func (v *reference) Name() string {
ret := C.GoString(C.git_reference_name(v.ptr))
runtime.KeepAlive(v)
return ret
}
func (v *reference) Type() git.ReferenceType {
ret := git.ReferenceType(C.git_reference_type(v.ptr))
runtime.KeepAlive(v)
return ret
}
func (v *reference) Target() *git.Oid {
ret := newOidFromC(C.git_reference_target(v.ptr))
runtime.KeepAlive(v)
return ret
}
func (v *reference) SymbolicTarget() string {
var ret string
cstr := C.git_reference_symbolic_target(v.ptr)
if cstr != nil {
return C.GoString(cstr)
}
runtime.KeepAlive(v)
return ret
}
func newSignatureFromC(sig *C.git_signature) *git.Signature {
// git stores minutes, go wants seconds
loc := time.FixedZone("", int(sig.when.offset)*60)
return &git.Signature{
C.GoString(sig.name),
C.GoString(sig.email),
time.Unix(int64(sig.when.time), 0).In(loc),
}
}