Skip to content

Commit c6c2e93

Browse files
committed
Merge branch 'push-cb' into next
2 parents ff6d4a7 + 803ef7d commit c6c2e93

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

remote.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ type HostkeyCertificate struct {
153153
}
154154

155155
type PushOptions struct {
156+
// Callbacks to use for this push operation
157+
RemoteCallbacks RemoteCallbacks
158+
156159
PbParallelism uint
157160
}
158161

@@ -211,7 +214,9 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
211214
url := C.GoString(_url)
212215
username_from_url := C.GoString(_username_from_url)
213216
ret, cred := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
214-
*_cred = cred.ptr
217+
if cred != nil {
218+
*_cred = cred.ptr
219+
}
215220
return int(ret)
216221
}
217222

@@ -591,6 +596,17 @@ func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
591596
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
592597
}
593598

599+
func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
600+
C.git_push_init_options(options, C.GIT_PUSH_OPTIONS_VERSION)
601+
if opts == nil {
602+
return
603+
}
604+
605+
options.pb_parallelism = C.uint(opts.PbParallelism)
606+
607+
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
608+
}
609+
594610
// Fetch performs a fetch operation. refspecs specifies which refspecs
595611
// to use for this fetch, use an empty list to use the refspecs from
596612
// the configuration; msg specifies what to use for the reflog
@@ -689,22 +705,19 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
689705
}
690706

691707
func (o *Remote) Push(refspecs []string, opts *PushOptions) error {
692-
var copts C.git_push_options
693-
C.git_push_init_options(&copts, C.GIT_PUSH_OPTIONS_VERSION)
694-
if opts != nil {
695-
copts.pb_parallelism = C.uint(opts.PbParallelism)
696-
}
697-
698708
crefspecs := C.git_strarray{}
699709
crefspecs.count = C.size_t(len(refspecs))
700710
crefspecs.strings = makeCStringsFromStrings(refspecs)
701711
defer freeStrarray(&crefspecs)
702712

713+
var coptions C.git_push_options
714+
populatePushOptions(&coptions, opts)
715+
defer untrackCalbacksPayload(&coptions.callbacks)
716+
703717
runtime.LockOSThread()
704718
defer runtime.UnlockOSThread()
705-
defer untrackCalbacksPayload(&copts.callbacks)
706719

707-
ret := C.git_remote_push(o.ptr, &crefspecs, &copts)
720+
ret := C.git_remote_push(o.ptr, &crefspecs, &coptions)
708721
if ret < 0 {
709722
return MakeGitError(ret)
710723
}

0 commit comments

Comments
 (0)