commit
6f79e6e60b
22
push.go
22
push.go
|
@ -31,6 +31,7 @@ func (p *Push) Free() {
|
|||
C.git_push_free(p.ptr)
|
||||
}
|
||||
|
||||
// This class is deprecated. Please use Remote.Push() instead
|
||||
func (remote *Remote) NewPush() (*Push, error) {
|
||||
|
||||
runtime.LockOSThread()
|
||||
|
@ -56,16 +57,6 @@ func (p *Push) Finish() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Push) UnpackOk() bool {
|
||||
|
||||
ret := C.git_push_unpack_ok(p.ptr)
|
||||
if ret == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func (p *Push) UpdateTips(sig *Signature, msg string) error {
|
||||
|
||||
var csig *C.git_signature = nil
|
||||
|
@ -155,17 +146,14 @@ type PushCallbacks struct {
|
|||
TransferProgress *PushTransferProgressCallback
|
||||
}
|
||||
|
||||
type PackbuilderProgressCallback func(stage int, current uint, total uint) int
|
||||
type PushTransferProgressCallback func(current uint, total uint, bytes uint) int
|
||||
|
||||
//export packbuilderProgress
|
||||
func packbuilderProgress(stage C.int, current C.uint, total C.uint, data unsafe.Pointer) C.int {
|
||||
return C.int((*(*PackbuilderProgressCallback)(data))(int(stage), uint(current), uint(total)))
|
||||
return C.int((*(*PackbuilderProgressCallback)(data))(int32(stage), uint32(current), uint32(total)))
|
||||
}
|
||||
|
||||
//export pushTransferProgress
|
||||
func pushTransferProgress(current C.uint, total C.uint, bytes C.size_t, data unsafe.Pointer) C.int {
|
||||
return C.int((*(*PushTransferProgressCallback)(data))(uint(current), uint(total), uint(bytes)))
|
||||
//export pushStructTransferProgress
|
||||
func pushStructTransferProgress(current C.uint, total C.uint, bytes C.size_t, data unsafe.Pointer) C.int {
|
||||
return C.int((*(*PushTransferProgressCallback)(data))(uint32(current), uint32(total), uint(bytes)))
|
||||
}
|
||||
|
||||
func (p *Push) SetCallbacks(callbacks PushCallbacks) {
|
||||
|
|
25
push_test.go
25
push_test.go
|
@ -48,10 +48,27 @@ func Test_Push_ToRemote(t *testing.T) {
|
|||
})
|
||||
checkFatal(t, err)
|
||||
|
||||
if !push.UnpackOk() {
|
||||
t.Fatalf("unable to unpack")
|
||||
}
|
||||
|
||||
defer remote.Free()
|
||||
defer repo.Free()
|
||||
}
|
||||
|
||||
func TestRemotePush(t *testing.T) {
|
||||
repo := createBareTestRepo(t)
|
||||
defer os.RemoveAll(repo.Path())
|
||||
localRepo := createTestRepo(t)
|
||||
defer os.RemoveAll(localRepo.Workdir())
|
||||
|
||||
remote, err := localRepo.CreateRemote("test_push", repo.Path())
|
||||
checkFatal(t, err)
|
||||
|
||||
seedTestRepo(t, localRepo)
|
||||
|
||||
err = remote.Push([]string{"refs/heads/master"}, nil, nil, "")
|
||||
checkFatal(t, err)
|
||||
|
||||
_, err = localRepo.LookupReference("refs/remotes/test_push/master")
|
||||
checkFatal(t, err)
|
||||
|
||||
_, err = repo.LookupReference("refs/heads/master")
|
||||
checkFatal(t, err)
|
||||
}
|
||||
|
|
78
remote.go
78
remote.go
|
@ -53,6 +53,9 @@ type CredentialsCallback func(url string, username_from_url string, allowed_type
|
|||
type TransferProgressCallback func(stats TransferProgress) ErrorCode
|
||||
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
|
||||
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
|
||||
type PackbuilderProgressCallback func(stage int32, current, total uint32) ErrorCode
|
||||
type PushTransferProgressCallback func(current, total uint32, bytes uint) ErrorCode
|
||||
type PushUpdateReferenceCallback func(refname, status string) ErrorCode
|
||||
|
||||
type RemoteCallbacks struct {
|
||||
SidebandProgressCallback TransportMessageCallback
|
||||
|
@ -61,8 +64,12 @@ type RemoteCallbacks struct {
|
|||
TransferProgressCallback
|
||||
UpdateTipsCallback
|
||||
CertificateCheckCallback
|
||||
PackProgressCallback PackbuilderProgressCallback
|
||||
PushTransferProgressCallback
|
||||
PushUpdateReferenceCallback
|
||||
}
|
||||
|
||||
|
||||
type Remote struct {
|
||||
ptr *C.git_remote
|
||||
callbacks RemoteCallbacks
|
||||
|
@ -216,6 +223,40 @@ func certificateCheckCallback(_cert *C.git_cert, _valid C.int, _host *C.char, da
|
|||
return int(callbacks.CertificateCheckCallback(&cert, valid, host))
|
||||
}
|
||||
|
||||
//export packProgressCallback
|
||||
func packProgressCallback(stage C.int, current, total C.uint, data unsafe.Pointer) int {
|
||||
callbacks := (*RemoteCallbacks)(data)
|
||||
|
||||
if callbacks.PackProgressCallback == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(callbacks.PackProgressCallback(int32(stage), uint32(current), uint32(total)))
|
||||
}
|
||||
|
||||
//export pushTransferProgressCallback
|
||||
func pushTransferProgressCallback(current, total C.uint, bytes C.size_t, data unsafe.Pointer) int {
|
||||
callbacks := (*RemoteCallbacks)(data)
|
||||
if callbacks.PushTransferProgressCallback == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(callbacks.PushTransferProgressCallback(uint32(current), uint32(total), uint(bytes)))
|
||||
}
|
||||
|
||||
//export pushUpdateReferenceCallback
|
||||
func pushUpdateReferenceCallback(refname, status *C.char, data unsafe.Pointer) int {
|
||||
callbacks := (*RemoteCallbacks)(data)
|
||||
|
||||
if callbacks.PushUpdateReferenceCallback == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return int(callbacks.PushUpdateReferenceCallback(C.GoString(refname), C.GoString(status)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
func RemoteIsValidName(name string) bool {
|
||||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
|
@ -650,3 +691,40 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
|
|||
|
||||
return heads, nil
|
||||
}
|
||||
|
||||
func (o *Remote) Push(refspecs []string, opts *PushOptions, sig *Signature, msg string) error {
|
||||
var csig *C.git_signature = nil
|
||||
if sig != nil {
|
||||
csig = sig.toC()
|
||||
defer C.free(unsafe.Pointer(csig))
|
||||
}
|
||||
|
||||
var cmsg *C.char
|
||||
if msg == "" {
|
||||
cmsg = nil
|
||||
} else {
|
||||
cmsg = C.CString(msg)
|
||||
defer C.free(unsafe.Pointer(cmsg))
|
||||
}
|
||||
|
||||
var copts C.git_push_options
|
||||
C.git_push_init_options(&copts, C.GIT_PUSH_OPTIONS_VERSION)
|
||||
if opts != nil {
|
||||
copts.version = C.uint(opts.Version)
|
||||
copts.pb_parallelism = C.uint(opts.PbParallelism)
|
||||
}
|
||||
|
||||
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_push(o.ptr, &crefspecs, &copts, csig, cmsg)
|
||||
if ret < 0 {
|
||||
return MakeGitError(ret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 169497d1e7c238d2925577d1af3dc03e9a507cd3
|
||||
Subproject commit 4eb97ef3bf18403fbce351ae4cac673655d2886a
|
|
@ -71,12 +71,17 @@ void _go_git_setup_diff_notify_callbacks(git_diff_options *opts) {
|
|||
void _go_git_setup_callbacks(git_remote_callbacks *callbacks) {
|
||||
typedef int (*completion_cb)(git_remote_completion_type type, void *data);
|
||||
typedef int (*update_tips_cb)(const char *refname, const git_oid *a, const git_oid *b, void *data);
|
||||
typedef (*push_update_reference_cb)(const char *refname, const char *status, void *data);
|
||||
|
||||
callbacks->sideband_progress = (git_transport_message_cb)sidebandProgressCallback;
|
||||
callbacks->completion = (completion_cb)completionCallback;
|
||||
callbacks->credentials = (git_cred_acquire_cb)credentialsCallback;
|
||||
callbacks->transfer_progress = (git_transfer_progress_cb)transferProgressCallback;
|
||||
callbacks->update_tips = (update_tips_cb)updateTipsCallback;
|
||||
callbacks->certificate_check = (git_transport_certificate_check_cb) certificateCheckCallback;
|
||||
callbacks->pack_progress = (git_packbuilder_progress) packProgressCallback;
|
||||
callbacks->push_transfer_progress = (git_push_transfer_progress) pushTransferProgressCallback;
|
||||
callbacks->push_update_reference = (push_update_reference_cb) pushUpdateReferenceCallback;
|
||||
}
|
||||
|
||||
typedef int (*status_foreach_cb)(const char *ref, const char *msg, void *data);
|
||||
|
@ -88,7 +93,7 @@ int _go_git_push_status_foreach(git_push *push, void *data)
|
|||
|
||||
int _go_git_push_set_callbacks(git_push *push, void *packbuilder_progress_data, void *transfer_progress_data)
|
||||
{
|
||||
return git_push_set_callbacks(push, packbuilderProgress, packbuilder_progress_data, pushTransferProgress, transfer_progress_data);
|
||||
return git_push_set_callbacks(push, packbuilderProgress, packbuilder_progress_data, pushStructTransferProgress, transfer_progress_data);
|
||||
}
|
||||
|
||||
int _go_blob_chunk_cb(char *buffer, size_t maxLen, void *payload)
|
||||
|
|
Loading…
Reference in New Issue