From 84ce8645dec7c3b4fa675894ba06f674d71f1b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 9 May 2014 03:34:04 +0200 Subject: [PATCH] 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. --- remote.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/remote.go b/remote.go index 74ebe27..e118e34 100644 --- a/remote.go +++ b/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) }