diff options
| author | Carlos Martín Nieto <[email protected]> | 2015-08-31 19:58:29 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2015-08-31 19:58:29 +0200 |
| commit | 6d3a3499f1639a6272e334f9f74b1e0cf6b0bb49 (patch) | |
| tree | 04b27dfdf1faadcaff6ca40fa27d8edd690045d1 /clone.go | |
| parent | 157593f38da780c4f6cb6dc61275b9b36a3327bf (diff) | |
| parent | 4090c401c8bf3f062e898f75bde01e2ef27b3911 (diff) | |
Merge branch 'master-v23'
Diffstat (limited to 'clone.go')
| -rw-r--r-- | clone.go | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -11,19 +11,17 @@ import ( "unsafe" ) -type RemoteCreateCallback func(repo Repository, name, url string) (*Remote, ErrorCode) +type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, ErrorCode) type CloneOptions struct { *CheckoutOpts - *RemoteCallbacks + *FetchOptions Bare bool CheckoutBranch string RemoteCreateCallback RemoteCreateCallback } func Clone(url string, path string, options *CloneOptions) (*Repository, error) { - repo := new(Repository) - curl := C.CString(url) defer C.free(unsafe.Pointer(curl)) @@ -40,30 +38,33 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_clone(&repo.ptr, curl, cpath, copts) + + var ptr *C.git_repository + ret := C.git_clone(&ptr, curl, cpath, copts) + freeCheckoutOpts(&copts.checkout_opts) if ret < 0 { return nil, MakeGitError(ret) } - runtime.SetFinalizer(repo, (*Repository).Free) - return repo, nil + return newRepositoryFromC(ptr), nil } //export remoteCreateCallback func remoteCreateCallback(cremote unsafe.Pointer, crepo unsafe.Pointer, cname, curl *C.char, payload unsafe.Pointer) C.int { name := C.GoString(cname) url := C.GoString(curl) - repo := Repository{(*C.git_repository)(crepo)} + repo := newRepositoryFromC((*C.git_repository)(crepo)) + // We don't own this repository, so make sure we don't try to free it + runtime.SetFinalizer(repo, nil) if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok { remote, err := opts.RemoteCreateCallback(repo, name, url) + // clear finalizer as the calling C function will + // free the remote itself + runtime.SetFinalizer(remote, nil) if err == ErrOk && remote != nil { - // clear finalizer as the calling C function will - // free the remote itself - runtime.SetFinalizer(remote, nil) - cptr := (**C.git_remote)(cremote) *cptr = remote.ptr } else if err == ErrOk && remote == nil { @@ -83,7 +84,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) { return } populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts) - populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks) + populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions) ptr.bare = cbool(opts.Bare) if opts.RemoteCreateCallback != nil { |
