summaryrefslogtreecommitdiff
path: root/remote.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-10-26 21:44:16 +0100
committerCarlos Martín Nieto <[email protected]>2015-10-26 21:44:16 +0100
commit749963ce55c6391bf7222057b037344a0cb837cf (patch)
treeb0b8d11250139b37a76c6ead494114411c2970dc /remote.go
parentc4868aef6c3e22a5c339dea4dd5406bfc0bd095b (diff)
parent367cd8eb9b84538933774befa76c099298c32c81 (diff)
Merge pull request #266 from clns/update-libgit2
[next] Update libgit2 to 821131f
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/remote.go b/remote.go
index b3aba54..a216513 100644
--- a/remote.go
+++ b/remote.go
@@ -112,6 +112,9 @@ type FetchOptions struct {
//
// The default is to auto-follow tags.
DownloadTags DownloadTags
+
+ // Headers are extra headers for the fetch operation.
+ Headers []string
}
type Remote struct {
@@ -157,6 +160,9 @@ type PushOptions struct {
RemoteCallbacks RemoteCallbacks
PbParallelism uint
+
+ // Headers are extra headers for the push operation.
+ Headers []string
}
type RemoteHead struct {
@@ -594,6 +600,10 @@ func populateFetchOptions(options *C.git_fetch_options, opts *FetchOptions) {
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)
+
+ options.custom_headers = C.git_strarray{}
+ options.custom_headers.count = C.size_t(len(opts.Headers))
+ options.custom_headers.strings = makeCStringsFromStrings(opts.Headers)
}
func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
@@ -604,6 +614,10 @@ func populatePushOptions(options *C.git_push_options, opts *PushOptions) {
options.pb_parallelism = C.uint(opts.PbParallelism)
+ options.custom_headers = C.git_strarray{}
+ options.custom_headers.count = C.size_t(len(opts.Headers))
+ options.custom_headers.strings = makeCStringsFromStrings(opts.Headers)
+
populateRemoteCallbacks(&options.callbacks, &opts.RemoteCallbacks)
}
@@ -626,6 +640,7 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
var coptions C.git_fetch_options
populateFetchOptions(&coptions, opts)
defer untrackCalbacksPayload(&coptions.callbacks)
+ defer freeStrarray(&coptions.custom_headers)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@@ -637,22 +652,34 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
return nil
}
-func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks) error {
- return o.Connect(ConnectDirectionFetch, callbacks)
+func (o *Remote) ConnectFetch(callbacks *RemoteCallbacks, headers []string) error {
+ return o.Connect(ConnectDirectionFetch, callbacks, headers)
}
-func (o *Remote) ConnectPush(callbacks *RemoteCallbacks) error {
- return o.Connect(ConnectDirectionPush, callbacks)
+func (o *Remote) ConnectPush(callbacks *RemoteCallbacks, headers []string) error {
+ return o.Connect(ConnectDirectionPush, callbacks, headers)
}
-func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks) error {
+// Connect opens a connection to a remote.
+//
+// The transport is selected based on the URL. The direction argument
+// is due to a limitation of the git protocol (over TCP or SSH) which
+// starts up a specific binary which can only do the one or the other.
+//
+// 'headers' are extra HTTP headers to use in this connection.
+func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks, headers []string) error {
var ccallbacks C.git_remote_callbacks
populateRemoteCallbacks(&ccallbacks, callbacks)
+ cheaders := C.git_strarray{}
+ cheaders.count = C.size_t(len(headers))
+ cheaders.strings = makeCStringsFromStrings(headers)
+ defer freeStrarray(&cheaders)
+
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks); ret != 0 {
+ if ret := C.git_remote_connect(o.ptr, C.git_direction(direction), &ccallbacks, &cheaders); ret != 0 {
return MakeGitError(ret)
}
return nil
@@ -713,6 +740,7 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions) error {
var coptions C.git_push_options
populatePushOptions(&coptions, opts)
defer untrackCalbacksPayload(&coptions.callbacks)
+ defer freeStrarray(&coptions.custom_headers)
runtime.LockOSThread()
defer runtime.UnlockOSThread()