From 36e0a256fe79f87447bb730fda53e5cbc90eb47c Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Mon, 8 Jun 2015 04:11:21 +0200 Subject: Update to libgit2 b6011e29 --- remote.go | 184 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 91 insertions(+), 93 deletions(-) (limited to 'remote.go') diff --git a/remote.go b/remote.go index 72d3934..705bc0c 100644 --- a/remote.go +++ b/remote.go @@ -69,6 +69,51 @@ type RemoteCallbacks struct { PushUpdateReferenceCallback } +type FetchPrune uint + +const ( + // Use the setting from the configuration + FetchPruneFallback FetchPrune = C.GIT_FETCH_PRUNE_FALLBACK + // Force pruning on + FetchPruneOn FetchPrune = C.GIT_FETCH_PRUNE + // Force pruning off + FetchNoPrune FetchPrune = C.GIT_FETCH_NO_PRUNE +) + +type DownloadTags uint + +const ( + + // Use the setting from the configuration. + DownloadTagsFallback DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK + // Ask the server for tags pointing to objects we're already + // downloading. + DownloadTagsAuto DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_AUTO + + // Don't ask for any tags beyond the refspecs. + DownloadTagsNone DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_NONE + + // Ask for the all the tags. + DownloadTagsAll DownloadTags = C.GIT_REMOTE_DOWNLOAD_TAGS_ALL +) + +type FetchOptions struct { + // Callbacks to use for this fetch operation + RemoteCallbacks RemoteCallbacks + // Whether to perform a prune after the fetch + Prune FetchPrune + // Whether to write the results to FETCH_HEAD. Defaults to + // on. Leave this default in order to behave like git. + UpdateFetchhead bool + + // Determines how to behave regarding tags on the remote, such + // as auto-downloading tags for objects we're downloading or + // downloading all of them. + // + // The default is to auto-follow tags. + DownloadTags DownloadTags +} + type Remote struct { ptr *C.git_remote callbacks RemoteCallbacks @@ -267,23 +312,6 @@ func RemoteIsValidName(name string) bool { return false } -func (r *Remote) SetCallbacks(callbacks *RemoteCallbacks) error { - r.callbacks = *callbacks - - var ccallbacks C.git_remote_callbacks - populateRemoteCallbacks(&ccallbacks, &r.callbacks) - - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - ecode := C.git_remote_set_callbacks(r.ptr, &ccallbacks) - if ecode < 0 { - return MakeGitError(ecode) - } - - return nil -} - func (r *Remote) Free() { runtime.SetFinalizer(r, nil) C.git_remote_free(r.ptr) @@ -359,18 +387,16 @@ func (repo *Repository) CreateRemoteWithFetchspec(name string, url string, fetch return remote, nil } -func (repo *Repository) CreateAnonymousRemote(url, fetch string) (*Remote, error) { +func (repo *Repository) CreateAnonymousRemote(url string) (*Remote, error) { remote := &Remote{} curl := C.CString(url) defer C.free(unsafe.Pointer(curl)) - cfetch := C.CString(fetch) - defer C.free(unsafe.Pointer(cfetch)) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl, cfetch) + ret := C.git_remote_create_anonymous(&remote.ptr, repo.ptr, curl) if ret < 0 { return nil, MakeGitError(ret) } @@ -395,18 +421,6 @@ func (repo *Repository) LookupRemote(name string) (*Remote, error) { return remote, nil } -func (o *Remote) Save() error { - - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - ret := C.git_remote_save(o.ptr) - if ret < 0 { - return MakeGitError(ret) - } - return nil -} - func (o *Remote) Owner() Repository { return Repository{C.git_remote_owner(o.ptr)} } @@ -423,42 +437,48 @@ func (o *Remote) PushUrl() string { return C.GoString(C.git_remote_pushurl(o.ptr)) } -func (o *Remote) SetUrl(url string) error { +func (o *Repository) RemoteSetUrl(remote, url string) error { curl := C.CString(url) defer C.free(unsafe.Pointer(curl)) + cremote := C.CString(remote) + defer C.free(unsafe.Pointer(cremote)) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_set_url(o.ptr, curl) + ret := C.git_remote_set_url(o.ptr, cremote, curl) if ret < 0 { return MakeGitError(ret) } return nil } -func (o *Remote) SetPushUrl(url string) error { +func (o *Repository) RemoteSetPushUrl(remote, url string) error { curl := C.CString(url) defer C.free(unsafe.Pointer(curl)) + cremote := C.CString(remote) + defer C.free(unsafe.Pointer(cremote)) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_set_pushurl(o.ptr, curl) + ret := C.git_remote_set_pushurl(o.ptr, cremote, curl) if ret < 0 { return MakeGitError(ret) } return nil } -func (o *Remote) AddFetch(refspec string) error { +func (o *Repository) RemoteAddFetch(remote, refspec string) error { crefspec := C.CString(refspec) defer C.free(unsafe.Pointer(crefspec)) + cremote := C.CString(remote) + defer C.free(unsafe.Pointer(cremote)) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_add_fetch(o.ptr, crefspec) + ret := C.git_remote_add_fetch(o.ptr, cremote, crefspec) if ret < 0 { return MakeGitError(ret) } @@ -519,30 +539,16 @@ func (o *Remote) FetchRefspecs() ([]string, error) { return refspecs, nil } -func (o *Remote) SetFetchRefspecs(refspecs []string) error { - crefspecs := C.git_strarray{} - crefspecs.count = C.size_t(len(refspecs)) - crefspecs.strings = makeCStringsFromStrings(refspecs) - defer freeStrarray(&crefspecs) - - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - ret := C.git_remote_set_fetch_refspecs(o.ptr, &crefspecs) - if ret < 0 { - return MakeGitError(ret) - } - return nil -} - -func (o *Remote) AddPush(refspec string) error { +func (o *Repository) RemoteAddPush(remote, refspec string) error { crefspec := C.CString(refspec) defer C.free(unsafe.Pointer(crefspec)) + cremote := C.CString(remote) + defer C.free(unsafe.Pointer(cremote)) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_add_push(o.ptr, crefspec) + ret := C.git_remote_add_push(o.ptr, cremote, crefspec) if ret < 0 { return MakeGitError(ret) } @@ -564,43 +570,26 @@ func (o *Remote) PushRefspecs() ([]string, error) { return refspecs, nil } -func (o *Remote) SetPushRefspecs(refspecs []string) error { - crefspecs := C.git_strarray{} - crefspecs.count = C.size_t(len(refspecs)) - crefspecs.strings = makeCStringsFromStrings(refspecs) - defer freeStrarray(&crefspecs) - - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - ret := C.git_remote_set_push_refspecs(o.ptr, &crefspecs) - if ret < 0 { - return MakeGitError(ret) - } - return nil -} - -func (o *Remote) ClearRefspecs() { - C.git_remote_clear_refspecs(o.ptr) -} - func (o *Remote) RefspecCount() uint { return uint(C.git_remote_refspec_count(o.ptr)) } -func (o *Remote) SetUpdateFetchHead(val bool) { - C.git_remote_set_update_fetchhead(o.ptr, cbool(val)) -} - -func (o *Remote) UpdateFetchHead() bool { - return C.git_remote_update_fetchhead(o.ptr) > 0 +func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) { + C.git_fetch_init_options(options, C.GIT_FETCH_OPTIONS_VERSION) + if opts == nil { + return; + } + populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks) + options.prune = C.git_fetch_prune_t(opts.Prune) + options.update_fetchhead = cbool(opts.UpdateFetchhead) + options.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags) } // Fetch performs a fetch operation. refspecs specifies which refspecs // to use for this fetch, use an empty list to use the refspecs from // the configuration; msg specifies what to use for the reflog // entries. Leave "" to use defaults. -func (o *Remote) Fetch(refspecs []string, msg string) error { +func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error { var cmsg *C.char = nil if msg != "" { @@ -613,29 +602,35 @@ func (o *Remote) Fetch(refspecs []string, msg string) error { crefspecs.strings = makeCStringsFromStrings(refspecs) defer freeStrarray(&crefspecs) + var coptions C.git_fetch_options + populateFetchOptions(&coptions, opts); + runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_fetch(o.ptr, &crefspecs, cmsg) + ret := C.git_remote_fetch(o.ptr, &crefspecs, &coptions, cmsg) if ret < 0 { return MakeGitError(ret) } return nil } -func (o *Remote) ConnectFetch() error { - return o.Connect(ConnectDirectionFetch) +func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks) error { + return o.Connect(ConnectDirectionFetch, callbacks) } -func (o *Remote) ConnectPush() error { - return o.Connect(ConnectDirectionPush) +func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error { + return o.Connect(ConnectDirectionPush, callbacks) } -func (o *Remote) Connect(direction ConnectDirection) error { +func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error { + var ccallbacks C.git_remote_callbacks; + populateRemoteCallbacks(&ccallbacks, callbacks) + runtime.LockOSThread() defer runtime.UnlockOSThread() - if ret := C.git_remote_connect(o.ptr, C.git_direction(direction)); ret != 0 { + if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks); ret != 0 { return MakeGitError(ret) } return nil @@ -713,11 +708,14 @@ func (o *Remote) PruneRefs() bool { return C.git_remote_prune_refs(o.ptr) > 0 } -func (o *Remote) Prune() error { +func (o *Remote) Prune(callbacks *RemoteCallbacks) error { + var ccallbacks C.git_remote_callbacks; + populateRemoteCallbacks(&ccallbacks, callbacks) + runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_remote_prune(o.ptr) + ret := C.git_remote_prune(o.ptr, &ccallbacks) if ret < 0 { return MakeGitError(ret) } -- cgit v1.2.3