Support git_remote_create_with_opts #733

Merged
bc-lee merged 4 commits from feature/645-git-remote-create-with-opts into master 2021-02-03 20:58:32 -06:00
1 changed files with 16 additions and 16 deletions
Showing only changes of commit 38f8bdaa95 - Show all commits

View File

@ -566,9 +566,9 @@ func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOpt
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
opts := populateRemoteCreateOptions(c.repo, option) copts := populateRemoteCreateOptions(&C.git_remote_create_options{}, option, c.repo)
defer freeRemoteCreateOptions(opts) defer freeRemoteCreateOptions(copts)
ret := C.git_remote_create_with_opts(&remote.ptr, curl, opts) ret := C.git_remote_create_with_opts(&remote.ptr, curl, copts)
runtime.KeepAlive(c.repo) runtime.KeepAlive(c.repo)
if ret < 0 { if ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
@ -1074,7 +1074,7 @@ func DefaultRemoteCreateOptions() (*RemoteCreateOptions, error) {
opts := C.git_remote_create_options{} opts := C.git_remote_create_options{}
ecode := C.git_remote_create_options_init(&opts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION) ecode := C.git_remote_create_options_init(&opts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION)
if int(ecode) != 0 { if ecode < 0 {
return nil, MakeGitError(ecode) return nil, MakeGitError(ecode)
} }
@ -1083,21 +1083,21 @@ func DefaultRemoteCreateOptions() (*RemoteCreateOptions, error) {
}, nil }, nil
} }
func populateRemoteCreateOptions(repository *Repository, opts *RemoteCreateOptions) (copts *C.git_remote_create_options) { func populateRemoteCreateOptions(copts *C.git_remote_create_options, opts *RemoteCreateOptions, repo *Repository) *C.git_remote_create_options {
if repository == nil || opts == nil { C.git_remote_create_options_init(copts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION)
return if opts == nil {
return nil
} }
cName := C.CString(opts.Name) var cRepository *C.git_repository
cFetchSpec := C.CString(opts.FetchSpec) if repo != nil {
cRepository = repo.ptr
copts = &C.git_remote_create_options{
version: C.GIT_REMOTE_CREATE_OPTIONS_VERSION,
repository: repository.ptr,
name: cName,
fetchspec: cFetchSpec,
flags: C.uint(opts.Flags),
} }
copts.repository = cRepository
copts.name = C.CString(opts.Name)
copts.fetchspec = C.CString(opts.FetchSpec)
copts.flags = C.uint(opts.Flags)
return copts return copts
} }