Updated remote.go to handle various comments on code review.
- Use consistent names for type/function names. - Removes unnecessary Repository pointers that can be collected from RemoteCollection. - Add runtime.KeepAlive to make the pointer happy.
This commit is contained in:
parent
5551581893
commit
96aacc1f1d
24
remote.go
24
remote.go
|
@ -18,21 +18,21 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RemoteCreate uint
|
// RemoteCreateOptionsFlag is Remote creation options flags
|
||||||
|
type RemoteCreateOptionsFlag uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Ignore the repository apply.insteadOf configuration
|
// Ignore the repository apply.insteadOf configuration
|
||||||
RemoteCreateSkipInsteadof RemoteCreate = C.GIT_REMOTE_CREATE_SKIP_INSTEADOF
|
RemoteCreateSkipInsteadof RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_INSTEADOF
|
||||||
// Don't build a fetchspec from the name if none is set
|
// Don't build a fetchspec from the name if none is set
|
||||||
RemoteCreateSkipDefaultFetchspec RemoteCreate = C.GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
|
RemoteCreateSkipDefaultFetchspec RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
|
||||||
)
|
)
|
||||||
|
|
||||||
// RemoteCreateOptions contains options for creating a remote
|
// RemoteCreateOptions contains options for creating a remote
|
||||||
type RemoteCreateOptions struct {
|
type RemoteCreateOptions struct {
|
||||||
Repository *Repository
|
|
||||||
Name string
|
Name string
|
||||||
FetchSpec string
|
FetchSpec string
|
||||||
Flags RemoteCreate
|
Flags RemoteCreateOptionsFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransferProgress struct {
|
type TransferProgress struct {
|
||||||
|
@ -556,7 +556,7 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RemoteCollection) CreateOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
|
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
|
||||||
remote := &Remote{repo: c.repo}
|
remote := &Remote{repo: c.repo}
|
||||||
|
|
||||||
curl := C.CString(url)
|
curl := C.CString(url)
|
||||||
|
@ -565,9 +565,10 @@ func (c *RemoteCollection) CreateOptions(url string, option *RemoteCreateOptions
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
opts := remoteCreateOptionsToC(option)
|
opts := populateRemoteCreateOptions(c.repo, option)
|
||||||
defer freeRemoteCreateOptions(opts)
|
defer freeRemoteCreateOptions(opts)
|
||||||
ret := C.git_remote_create_with_opts(&remote.ptr, curl, opts)
|
ret := C.git_remote_create_with_opts(&remote.ptr, curl, opts)
|
||||||
|
runtime.KeepAlive(c.repo)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
@ -1077,13 +1078,12 @@ func DefaultRemoteCreateOptions() (*RemoteCreateOptions, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RemoteCreateOptions{
|
return &RemoteCreateOptions{
|
||||||
Repository: nil,
|
Flags: RemoteCreateOptionsFlag(opts.flags),
|
||||||
Flags: 0,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func remoteCreateOptionsToC(opts *RemoteCreateOptions) (copts *C.git_remote_create_options) {
|
func populateRemoteCreateOptions(repository *Repository, opts *RemoteCreateOptions) (copts *C.git_remote_create_options) {
|
||||||
if opts == nil {
|
if repository == nil || opts == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1092,7 +1092,7 @@ func remoteCreateOptionsToC(opts *RemoteCreateOptions) (copts *C.git_remote_crea
|
||||||
|
|
||||||
copts = &C.git_remote_create_options{
|
copts = &C.git_remote_create_options{
|
||||||
version: C.GIT_REMOTE_CREATE_OPTIONS_VERSION,
|
version: C.GIT_REMOTE_CREATE_OPTIONS_VERSION,
|
||||||
repository: opts.Repository.ptr,
|
repository: repository.ptr,
|
||||||
name: cName,
|
name: cName,
|
||||||
fetchspec: cFetchSpec,
|
fetchspec: cFetchSpec,
|
||||||
flags: C.uint(opts.Flags),
|
flags: C.uint(opts.Flags),
|
||||||
|
|
|
@ -92,11 +92,10 @@ func TestRemoteConnectOption(t *testing.T) {
|
||||||
|
|
||||||
option, err := DefaultRemoteCreateOptions()
|
option, err := DefaultRemoteCreateOptions()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
option.Repository = repo
|
|
||||||
option.Name = "origin"
|
option.Name = "origin"
|
||||||
option.Flags = RemoteCreateSkipInsteadof
|
option.Flags = RemoteCreateSkipInsteadof
|
||||||
|
|
||||||
remote, err := repo.Remotes.CreateOptions("https://github.com/libgit2/TestGitRepository", option)
|
remote, err := repo.Remotes.CreateWithOptions("https://github.com/libgit2/TestGitRepository", option)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
err = remote.ConnectFetch(nil, nil, nil)
|
err = remote.ConnectFetch(nil, nil, nil)
|
||||||
|
|
Loading…
Reference in New Issue