Skip to content

Commit a572b15

Browse files
AaronOcarlosmn
authored andcommitted
Add back support for RemoteCallbacks in Remote.Push()
1 parent c0c6cae commit a572b15

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

remote.go

Lines changed: 19 additions & 8 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

@@ -591,6 +594,17 @@ func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
591594
options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
592595
}
593596

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

691705
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-
698706
crefspecs := C.git_strarray{}
699707
crefspecs.count = C.size_t(len(refspecs))
700708
crefspecs.strings = makeCStringsFromStrings(refspecs)
701709
defer freeStrarray(&crefspecs)
702710

711+
var coptions C.git_push_options
712+
populatePushOptions(&coptions, opts)
713+
defer untrackCalbacksPayload(&coptions.callbacks)
714+
703715
runtime.LockOSThread()
704716
defer runtime.UnlockOSThread()
705-
defer untrackCalbacksPayload(&copts.callbacks)
706717

707-
ret := C.git_remote_push(o.ptr, &crefspecs, &copts)
718+
ret := C.git_remote_push(o.ptr, &crefspecs, &coptions)
708719
if ret < 0 {
709720
return MakeGitError(ret)
710721
}

0 commit comments

Comments
 (0)