Make the network code use handles
This wasn't ported together with the rest, but it does exhibit the same issues, so let's port it over now.
This commit is contained in:
parent
53fd8ea011
commit
c00a05586b
12
clone.go
12
clone.go
|
@ -28,18 +28,20 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
|
||||||
cpath := C.CString(path)
|
cpath := C.CString(path)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
var copts C.git_clone_options
|
copts := (*C.git_clone_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_clone_options{}))))
|
||||||
populateCloneOptions(&copts, options)
|
populateCloneOptions(copts, options)
|
||||||
defer freeCheckoutOpts(&copts.checkout_opts)
|
|
||||||
|
|
||||||
if len(options.CheckoutBranch) != 0 {
|
if len(options.CheckoutBranch) != 0 {
|
||||||
copts.checkout_branch = C.CString(options.CheckoutBranch)
|
copts.checkout_branch = C.CString(options.CheckoutBranch)
|
||||||
defer C.free(unsafe.Pointer(copts.checkout_branch))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
ret := C.git_clone(&repo.ptr, curl, cpath, &copts)
|
ret := C.git_clone(&repo.ptr, curl, cpath, copts)
|
||||||
|
freeCheckoutOpts(&copts.checkout_opts)
|
||||||
|
C.free(unsafe.Pointer(copts.checkout_branch))
|
||||||
|
C.free(unsafe.Pointer(copts))
|
||||||
|
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
26
remote.go
26
remote.go
|
@ -129,12 +129,12 @@ func populateRemoteCallbacks(ptr *C.git_remote_callbacks, callbacks *RemoteCallb
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
C._go_git_setup_callbacks(ptr)
|
C._go_git_setup_callbacks(ptr)
|
||||||
ptr.payload = unsafe.Pointer(callbacks)
|
ptr.payload = pointerHandles.Track(callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export sidebandProgressCallback
|
//export sidebandProgressCallback
|
||||||
func sidebandProgressCallback(_str *C.char, _len C.int, data unsafe.Pointer) int {
|
func sidebandProgressCallback(_str *C.char, _len C.int, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.SidebandProgressCallback == nil {
|
if callbacks.SidebandProgressCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func sidebandProgressCallback(_str *C.char, _len C.int, data unsafe.Pointer) int
|
||||||
|
|
||||||
//export completionCallback
|
//export completionCallback
|
||||||
func completionCallback(completion_type C.git_remote_completion_type, data unsafe.Pointer) int {
|
func completionCallback(completion_type C.git_remote_completion_type, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.CompletionCallback == nil {
|
if callbacks.CompletionCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func completionCallback(completion_type C.git_remote_completion_type, data unsaf
|
||||||
|
|
||||||
//export credentialsCallback
|
//export credentialsCallback
|
||||||
func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int {
|
func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C.char, allowed_types uint, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.CredentialsCallback == nil {
|
if callbacks.CredentialsCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
|
||||||
|
|
||||||
//export transferProgressCallback
|
//export transferProgressCallback
|
||||||
func transferProgressCallback(stats *C.git_transfer_progress, data unsafe.Pointer) int {
|
func transferProgressCallback(stats *C.git_transfer_progress, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.TransferProgressCallback == nil {
|
if callbacks.TransferProgressCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ func transferProgressCallback(stats *C.git_transfer_progress, data unsafe.Pointe
|
||||||
|
|
||||||
//export updateTipsCallback
|
//export updateTipsCallback
|
||||||
func updateTipsCallback(_refname *C.char, _a *C.git_oid, _b *C.git_oid, data unsafe.Pointer) int {
|
func updateTipsCallback(_refname *C.char, _a *C.git_oid, _b *C.git_oid, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.UpdateTipsCallback == nil {
|
if callbacks.UpdateTipsCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ func updateTipsCallback(_refname *C.char, _a *C.git_oid, _b *C.git_oid, data uns
|
||||||
|
|
||||||
//export certificateCheckCallback
|
//export certificateCheckCallback
|
||||||
func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, data unsafe.Pointer) int {
|
func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
// if there's no callback set, we need to make sure we fail if the library didn't consider this cert valid
|
// if there's no callback set, we need to make sure we fail if the library didn't consider this cert valid
|
||||||
if callbacks.CertificateCheckCallback == nil {
|
if callbacks.CertificateCheckCallback == nil {
|
||||||
if _valid == 1 {
|
if _valid == 1 {
|
||||||
|
@ -228,7 +228,7 @@ func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, da
|
||||||
|
|
||||||
//export packProgressCallback
|
//export packProgressCallback
|
||||||
func packProgressCallback(stage C.int, current, total C.uint, data unsafe.Pointer) int {
|
func packProgressCallback(stage C.int, current, total C.uint, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
|
|
||||||
if callbacks.PackProgressCallback == nil {
|
if callbacks.PackProgressCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -239,7 +239,7 @@ func packProgressCallback(stage C.int, current, total C.uint, data unsafe.Pointe
|
||||||
|
|
||||||
//export pushTransferProgressCallback
|
//export pushTransferProgressCallback
|
||||||
func pushTransferProgressCallback(current, total C.uint, bytes C.size_t, data unsafe.Pointer) int {
|
func pushTransferProgressCallback(current, total C.uint, bytes C.size_t, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
if callbacks.PushTransferProgressCallback == nil {
|
if callbacks.PushTransferProgressCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ func pushTransferProgressCallback(current, total C.uint, bytes C.size_t, data un
|
||||||
|
|
||||||
//export pushUpdateReferenceCallback
|
//export pushUpdateReferenceCallback
|
||||||
func pushUpdateReferenceCallback(refname, status *C.char, data unsafe.Pointer) int {
|
func pushUpdateReferenceCallback(refname, status *C.char, data unsafe.Pointer) int {
|
||||||
callbacks := (*RemoteCallbacks)(data)
|
callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
|
||||||
|
|
||||||
if callbacks.PushUpdateReferenceCallback == nil {
|
if callbacks.PushUpdateReferenceCallback == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -286,6 +286,12 @@ func (r *Remote) SetCallbacks(callbacks *RemoteCallbacks) error {
|
||||||
|
|
||||||
func (r *Remote) Free() {
|
func (r *Remote) Free() {
|
||||||
runtime.SetFinalizer(r, nil)
|
runtime.SetFinalizer(r, nil)
|
||||||
|
|
||||||
|
callbacks := C.git_remote_get_callbacks(r.ptr)
|
||||||
|
if callbacks != nil && callbacks.payload != nil {
|
||||||
|
pointerHandles.Untrack(callbacks.payload)
|
||||||
|
}
|
||||||
|
|
||||||
C.git_remote_free(r.ptr)
|
C.git_remote_free(r.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue