Remote: specify the refspecs and callbacks in Fetch
The Remote interface mixes the configuration of a remote with overriding the configuration for a paritcular operation. This makes the remotes trickier to use than they should be. Move towards letting the user specify the refspecs and callbacks they want for a particular Fetch() operation intsead of setting it for a Remote object that they then need to throw away.
This commit is contained in:
parent
f5e1252d6e
commit
84ce8645de
33
remote.go
33
remote.go
|
@ -409,7 +409,7 @@ func (o *Remote) PushRefspecs() ([]string, error) {
|
|||
return refspecs, nil
|
||||
}
|
||||
|
||||
func (o *Remote) SetPushRefspecs(refspecs []string) error {
|
||||
func setPushRefspecs(remote *C.git_remote, refspecs []string) error {
|
||||
crefspecs := C.git_strarray{}
|
||||
crefspecs.count = C.size_t(len(refspecs))
|
||||
crefspecs.strings = makeCStringsFromStrings(refspecs)
|
||||
|
@ -418,13 +418,17 @@ func (o *Remote) SetPushRefspecs(refspecs []string) error {
|
|||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
ret := C.git_remote_set_push_refspecs(o.ptr, &crefspecs)
|
||||
ret := C.git_remote_set_push_refspecs(remote, &crefspecs)
|
||||
if ret < 0 {
|
||||
return MakeGitError(ret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Remote) SetPushRefspecs(refspecs []string) error {
|
||||
return setPushRefspecs(o.ptr, refspecs)
|
||||
}
|
||||
|
||||
func (o *Remote) ClearRefspecs() {
|
||||
C.git_remote_clear_refspecs(o.ptr)
|
||||
}
|
||||
|
@ -433,7 +437,24 @@ func (o *Remote) RefspecCount() uint {
|
|||
return uint(C.git_remote_refspec_count(o.ptr))
|
||||
}
|
||||
|
||||
func (o *Remote) Fetch(sig *Signature, msg string) error {
|
||||
func (o *Remote) Fetch(refspecs []string, callbacks *RemoteCallbacks, sig *Signature, msg string) error {
|
||||
|
||||
var remote *C.git_remote
|
||||
if ret := C.git_remote_dup(&remote, o.ptr); ret < 0 {
|
||||
return MakeGitError(ret)
|
||||
}
|
||||
defer C.git_remote_free(remote)
|
||||
|
||||
var ccallbacks C.git_remote_callbacks
|
||||
populateRemoteCallbacks(&ccallbacks, callbacks)
|
||||
C.git_remote_set_callbacks(remote, &ccallbacks)
|
||||
|
||||
if refspecs != nil {
|
||||
err := setPushRefspecs(remote, refspecs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var csig *C.git_signature = nil
|
||||
if sig != nil {
|
||||
|
@ -448,7 +469,11 @@ func (o *Remote) Fetch(sig *Signature, msg string) error {
|
|||
cmsg = C.CString(msg)
|
||||
defer C.free(unsafe.Pointer(cmsg))
|
||||
}
|
||||
ret := C.git_remote_fetch(o.ptr, csig, cmsg)
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
ret := C.git_remote_fetch(remote, csig, cmsg)
|
||||
if ret < 0 {
|
||||
return MakeGitError(ret)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue