Default signature
This commit is contained in:
parent
db5fa66b48
commit
e439b931a6
10
branch.go
10
branch.go
|
@ -96,7 +96,10 @@ func (repo *Repository) CreateBranch(branchName string, target *Commit, force bo
|
|||
cBranchName := C.CString(branchName)
|
||||
cForce := cbool(force)
|
||||
|
||||
cSignature := signature.toC()
|
||||
cSignature, err := signature.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(cSignature)
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -133,7 +136,10 @@ func (b *Branch) Move(newBranchName string, force bool, signature *Signature, ms
|
|||
cNewBranchName := C.CString(newBranchName)
|
||||
cForce := cbool(force)
|
||||
|
||||
cSignature := signature.toC()
|
||||
cSignature, err := signature.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(cSignature)
|
||||
|
||||
var cmsg *C.char
|
||||
|
|
48
commit.go
48
commit.go
|
@ -9,8 +9,6 @@ import "C"
|
|||
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Commit
|
||||
|
@ -68,49 +66,3 @@ func (c *Commit) ParentId(n uint) *Oid {
|
|||
func (c *Commit) ParentCount() uint {
|
||||
return uint(C.git_commit_parentcount(c.cast_ptr))
|
||||
}
|
||||
|
||||
// Signature
|
||||
|
||||
type Signature struct {
|
||||
Name string
|
||||
Email string
|
||||
When time.Time
|
||||
}
|
||||
|
||||
func newSignatureFromC(sig *C.git_signature) *Signature {
|
||||
// git stores minutes, go wants seconds
|
||||
loc := time.FixedZone("", int(sig.when.offset)*60)
|
||||
return &Signature{
|
||||
C.GoString(sig.name),
|
||||
C.GoString(sig.email),
|
||||
time.Unix(int64(sig.when.time), 0).In(loc),
|
||||
}
|
||||
}
|
||||
|
||||
// the offset in mintes, which is what git wants
|
||||
func (v *Signature) Offset() int {
|
||||
_, offset := v.When.Zone()
|
||||
return offset / 60
|
||||
}
|
||||
|
||||
func (sig *Signature) toC() *C.git_signature {
|
||||
|
||||
if sig == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
15
reference.go
15
reference.go
|
@ -36,7 +36,10 @@ func (v *Reference) SetSymbolicTarget(target string, sig *Signature, msg string)
|
|||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -61,7 +64,10 @@ func (v *Reference) SetTarget(target *Oid, sig *Signature, msg string) (*Referen
|
|||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -99,7 +105,10 @@ func (v *Reference) Rename(name string, force bool, sig *Signature, msg string)
|
|||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
|
10
remote.go
10
remote.go
|
@ -604,7 +604,10 @@ func (o *Remote) Fetch(refspecs []string, sig *Signature, msg string) error {
|
|||
|
||||
var csig *C.git_signature = nil
|
||||
if sig != nil {
|
||||
csig = sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
}
|
||||
|
||||
|
@ -696,7 +699,10 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
|
|||
func (o *Remote) Push(refspecs []string, opts *PushOptions, sig *Signature, msg string) error {
|
||||
var csig *C.git_signature = nil
|
||||
if sig != nil {
|
||||
csig = sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
}
|
||||
|
||||
|
|
|
@ -210,7 +210,10 @@ func (v *Repository) SetHead(refname string, sig *Signature, msg string) error {
|
|||
cname := C.CString(refname)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -230,7 +233,10 @@ func (v *Repository) SetHead(refname string, sig *Signature, msg string) error {
|
|||
}
|
||||
|
||||
func (v *Repository) SetHeadDetached(id *Oid, sig *Signature, msg string) error {
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -253,7 +259,10 @@ func (v *Repository) CreateReference(name string, id *Oid, force bool, sig *Sign
|
|||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -284,7 +293,10 @@ func (v *Repository) CreateSymbolicReference(name, target string, force bool, si
|
|||
ctarget := C.CString(target)
|
||||
defer C.free(unsafe.Pointer(ctarget))
|
||||
|
||||
csig := sig.toC()
|
||||
csig, err := sig.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
|
||||
var cmsg *C.char
|
||||
|
@ -352,10 +364,16 @@ func (v *Repository) CreateCommit(
|
|||
parentsarg = &cparents[0]
|
||||
}
|
||||
|
||||
authorSig := author.toC()
|
||||
authorSig, err := author.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(authorSig)
|
||||
|
||||
committerSig := committer.toC()
|
||||
committerSig, err := committer.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(committerSig)
|
||||
|
||||
runtime.LockOSThread()
|
||||
|
@ -384,7 +402,10 @@ func (v *Repository) CreateTag(
|
|||
cmessage := C.CString(message)
|
||||
defer C.free(unsafe.Pointer(cmessage))
|
||||
|
||||
taggerSig := tagger.toC()
|
||||
taggerSig, err := tagger.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(taggerSig)
|
||||
|
||||
ctarget := commit.gitObject.ptr
|
||||
|
@ -546,10 +567,16 @@ func (v *Repository) CreateNote(
|
|||
defer C.free(unsafe.Pointer(cref))
|
||||
}
|
||||
|
||||
authorSig := author.toC()
|
||||
authorSig, err := author.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(authorSig)
|
||||
|
||||
committerSig := committer.toC()
|
||||
committerSig, err := committer.toC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer C.git_signature_free(committerSig)
|
||||
|
||||
cnote := C.CString(note)
|
||||
|
@ -601,10 +628,16 @@ func (v *Repository) RemoveNote(ref string, author, committer *Signature, id *Oi
|
|||
defer C.free(unsafe.Pointer(cref))
|
||||
}
|
||||
|
||||
authorSig := author.toC()
|
||||
authorSig, err := author.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.git_signature_free(authorSig)
|
||||
|
||||
committerSig := committer.toC()
|
||||
committerSig, err := committer.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer C.git_signature_free(committerSig)
|
||||
|
||||
runtime.LockOSThread()
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package git
|
||||
|
||||
/*
|
||||
#include <git2.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Signature struct {
|
||||
Name string
|
||||
Email string
|
||||
When time.Time
|
||||
}
|
||||
|
||||
func newSignatureFromC(sig *C.git_signature) *Signature {
|
||||
// git stores minutes, go wants seconds
|
||||
loc := time.FixedZone("", int(sig.when.offset)*60)
|
||||
return &Signature{
|
||||
C.GoString(sig.name),
|
||||
C.GoString(sig.email),
|
||||
time.Unix(int64(sig.when.time), 0).In(loc),
|
||||
}
|
||||
}
|
||||
|
||||
// the offset in mintes, which is what git wants
|
||||
func (v *Signature) Offset() int {
|
||||
_, offset := v.When.Zone()
|
||||
return offset / 60
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (repo *Repository) DefaultSignature() (*Signature, error) {
|
||||
var out *C.git_signature
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
cErr := C.git_signature_default(&out, repo.ptr)
|
||||
if cErr < 0 {
|
||||
return nil, MakeGitError(cErr)
|
||||
}
|
||||
|
||||
defer C.git_signature_free(out)
|
||||
|
||||
return newSignatureFromC(out), nil
|
||||
}
|
18
submodule.go
18
submodule.go
|
@ -318,7 +318,10 @@ func (repo *Repository) ReloadAllSubmodules(force bool) error {
|
|||
|
||||
func (sub *Submodule) Update(init bool, opts *SubmoduleUpdateOptions) error {
|
||||
var copts C.git_submodule_update_options
|
||||
populateSubmoduleUpdateOptions(&copts, opts)
|
||||
err := populateSubmoduleUpdateOptions(&copts, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
@ -331,15 +334,22 @@ func (sub *Submodule) Update(init bool, opts *SubmoduleUpdateOptions) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *SubmoduleUpdateOptions) {
|
||||
func populateSubmoduleUpdateOptions(ptr *C.git_submodule_update_options, opts *SubmoduleUpdateOptions) error {
|
||||
C.git_submodule_update_init_options(ptr, C.GIT_SUBMODULE_UPDATE_OPTIONS_VERSION)
|
||||
|
||||
if opts == nil {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
|
||||
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
|
||||
ptr.clone_checkout_strategy = C.uint(opts.CloneCheckoutStrategy)
|
||||
ptr.signature = opts.Signature.toC()
|
||||
|
||||
sig, err := opts.Signature.toC()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ptr.signature = sig
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue