summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-06-10 13:03:53 +0200
committerCarlos Martín Nieto <[email protected]>2015-06-10 13:37:59 +0200
commitc00a05586b63df56a2c619e456229c1c9f785fa7 (patch)
tree5d3fb5ecb9b4c9c980d3b80a82c1c3069c6906e3
parent53fd8ea011483ce70a16332d877d6efd5bafb369 (diff)
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.
-rw-r--r--clone.go12
-rw-r--r--remote.go26
2 files changed, 23 insertions, 15 deletions
diff --git a/clone.go b/clone.go
index b796b6e..4de4aea 100644
--- a/clone.go
+++ b/clone.go
@@ -28,18 +28,20 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
- var copts C.git_clone_options
- populateCloneOptions(&copts, options)
- defer freeCheckoutOpts(&copts.checkout_opts)
+ copts := (*C.git_clone_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_clone_options{}))))
+ populateCloneOptions(copts, options)
if len(options.CheckoutBranch) != 0 {
copts.checkout_branch = C.CString(options.CheckoutBranch)
- defer C.free(unsafe.Pointer(copts.checkout_branch))
}
runtime.LockOSThread()
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 {
return nil, MakeGitError(ret)
}
diff --git a/remote.go b/remote.go
index 84750d3..b9acc71 100644
--- a/remote.go
+++ b/remote.go
@@ -129,12 +129,12 @@ func populateRemoteCallbacks(ptr *C.git_remote_callbacks, callbacks *RemoteCallb
return
}
C._go_git_setup_callbacks(ptr)
- ptr.payload = unsafe.Pointer(callbacks)
+ ptr.payload = pointerHandles.Track(callbacks)
}
//export sidebandProgressCallback
func sidebandProgressCallback(_str *C.char, _len C.int, data unsafe.Pointer) int {
- callbacks := (*RemoteCallbacks)(data)
+ callbacks := pointerHandles.Get(data).(*RemoteCallbacks)
if callbacks.SidebandProgressCallback == nil {
return 0
}
@@ -144,7 +144,7 @@ func sidebandProgressCallback(_str *C.char, _len C.int, data unsafe.Pointer) int
//export completionCallback
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 {
return 0
}
@@ -153,7 +153,7 @@ func completionCallback(completion_type C.git_remote_completion_type, data unsaf
//export credentialsCallback
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 {
return 0
}
@@ -166,7 +166,7 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
//export transferProgressCallback
func transferProgressCallback(stats *C.git_transfer_progress, data unsafe.Pointer) int {
- callbacks := (*RemoteCallbacks)(data)
+ callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
if callbacks.TransferProgressCallback == nil {
return 0
}
@@ -175,7 +175,7 @@ func transferProgressCallback(stats *C.git_transfer_progress, data unsafe.Pointe
//export updateTipsCallback
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 {
return 0
}
@@ -187,7 +187,7 @@ func updateTipsCallback(_refname *C.char, _a *C.git_oid, _b *C.git_oid, data uns
//export certificateCheckCallback
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 callbacks.CertificateCheckCallback == nil {
if _valid == 1 {
@@ -228,7 +228,7 @@ func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, da
//export packProgressCallback
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 {
return 0
@@ -239,7 +239,7 @@ func packProgressCallback(stage C.int, current, total C.uint, data unsafe.Pointe
//export pushTransferProgressCallback
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 {
return 0
}
@@ -249,7 +249,7 @@ func pushTransferProgressCallback(current, total C.uint, bytes C.size_t, data un
//export pushUpdateReferenceCallback
func pushUpdateReferenceCallback(refname, status *C.char, data unsafe.Pointer) int {
- callbacks := (*RemoteCallbacks)(data)
+ callbacks, _ := pointerHandles.Get(data).(*RemoteCallbacks)
if callbacks.PushUpdateReferenceCallback == nil {
return 0
@@ -286,6 +286,12 @@ func (r *Remote) SetCallbacks(callbacks *RemoteCallbacks) error {
func (r *Remote) Free() {
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)
}