Update to libgit2 master
This gets rid of the Push object. All network now goes through the Remote object.
This commit is contained in:
parent
dff9badc05
commit
d57246fb74
1
git.go
1
git.go
|
@ -2,6 +2,7 @@ package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
#include <git2/sys/openssl.h>
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
|
169
push.go
169
push.go
|
@ -1,169 +0,0 @@
|
||||||
package git
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <git2.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import (
|
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Push struct {
|
|
||||||
ptr *C.git_push
|
|
||||||
|
|
||||||
packbuilderProgress *PackbuilderProgressCallback
|
|
||||||
transferProgress *PushTransferProgressCallback
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPushFromC(cpush *C.git_push) *Push {
|
|
||||||
p := &Push{ptr: cpush}
|
|
||||||
runtime.SetFinalizer(p, (*Push).Free)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) Free() {
|
|
||||||
runtime.SetFinalizer(p, nil)
|
|
||||||
C.git_push_free(p.ptr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This class is deprecated. Please use Remote.Push() instead
|
|
||||||
func (remote *Remote) NewPush() (*Push, error) {
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
var cpush *C.git_push
|
|
||||||
ret := C.git_push_new(&cpush, remote.ptr)
|
|
||||||
if ret < 0 {
|
|
||||||
return nil, MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return newPushFromC(cpush), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) Finish() error {
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_push_finish(p.ptr)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) UpdateTips(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))
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_push_update_tips(p.ptr, csig, cmsg)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) AddRefspec(refspec string) error {
|
|
||||||
|
|
||||||
crefspec := C.CString(refspec)
|
|
||||||
defer C.free(unsafe.Pointer(crefspec))
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_push_add_refspec(p.ptr, crefspec)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type PushOptions struct {
|
|
||||||
Version uint
|
|
||||||
PbParallelism uint
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) SetOptions(opts PushOptions) error {
|
|
||||||
copts := C.git_push_options{version: C.uint(opts.Version), pb_parallelism: C.uint(opts.PbParallelism)}
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_push_set_options(p.ptr, &copts)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StatusForeachFunc func(ref string, msg string) int
|
|
||||||
|
|
||||||
//export statusForeach
|
|
||||||
func statusForeach(_ref *C.char, _msg *C.char, _data unsafe.Pointer) C.int {
|
|
||||||
ref := C.GoString(_ref)
|
|
||||||
msg := C.GoString(_msg)
|
|
||||||
|
|
||||||
cb := (*StatusForeachFunc)(_data)
|
|
||||||
|
|
||||||
return C.int((*cb)(ref, msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Push) StatusForeach(callback StatusForeachFunc) error {
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C._go_git_push_status_foreach(p.ptr, unsafe.Pointer(&callback))
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type PushCallbacks struct {
|
|
||||||
PackbuilderProgress *PackbuilderProgressCallback
|
|
||||||
TransferProgress *PushTransferProgressCallback
|
|
||||||
}
|
|
||||||
|
|
||||||
//export packbuilderProgress
|
|
||||||
func packbuilderProgress(stage C.int, current C.uint, total C.uint, data unsafe.Pointer) C.int {
|
|
||||||
return C.int((*(*PackbuilderProgressCallback)(data))(int32(stage), uint32(current), uint32(total)))
|
|
||||||
}
|
|
||||||
|
|
||||||
//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) {
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
// save callbacks so they don't get GC'd
|
|
||||||
p.packbuilderProgress = callbacks.PackbuilderProgress
|
|
||||||
p.transferProgress = callbacks.TransferProgress
|
|
||||||
|
|
||||||
C._go_git_push_set_callbacks(p.ptr, unsafe.Pointer(p.packbuilderProgress), unsafe.Pointer(p.transferProgress))
|
|
||||||
}
|
|
47
push_test.go
47
push_test.go
|
@ -3,55 +3,8 @@ package git
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Push_ToRemote(t *testing.T) {
|
|
||||||
repo := createBareTestRepo(t)
|
|
||||||
defer os.RemoveAll(repo.Path())
|
|
||||||
repo2 := createTestRepo(t)
|
|
||||||
defer os.RemoveAll(repo2.Workdir())
|
|
||||||
|
|
||||||
remote, err := repo2.CreateRemote("test_push", repo.Path())
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
index, err := repo2.Index()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
index.AddByPath("README")
|
|
||||||
|
|
||||||
err = index.Write()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
newTreeId, err := index.WriteTree()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
tree, err := repo2.LookupTree(newTreeId)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
sig := &Signature{Name: "Rand Om Hacker", Email: "random@hacker.com", When: time.Now()}
|
|
||||||
// this should cause master branch to be created if it does not already exist
|
|
||||||
_, err = repo2.CreateCommit("HEAD", sig, sig, "message", tree)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
push, err := remote.NewPush()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
err = push.AddRefspec("refs/heads/master")
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
err = push.Finish()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
err = push.StatusForeach(func(ref string, msg string) int {
|
|
||||||
return 0
|
|
||||||
})
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
defer remote.Free()
|
|
||||||
defer repo.Free()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRemotePush(t *testing.T) {
|
func TestRemotePush(t *testing.T) {
|
||||||
repo := createBareTestRepo(t)
|
repo := createBareTestRepo(t)
|
||||||
defer os.RemoveAll(repo.Path())
|
defer os.RemoveAll(repo.Path())
|
||||||
|
|
|
@ -108,6 +108,10 @@ type HostkeyCertificate struct {
|
||||||
HashSHA1 [20]byte
|
HashSHA1 [20]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PushOptions struct {
|
||||||
|
PbParallelism uint
|
||||||
|
}
|
||||||
|
|
||||||
type RemoteHead struct {
|
type RemoteHead struct {
|
||||||
Id *Oid
|
Id *Oid
|
||||||
Name string
|
Name string
|
||||||
|
@ -710,7 +714,6 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions, sig *Signature, msg
|
||||||
var copts C.git_push_options
|
var copts C.git_push_options
|
||||||
C.git_push_init_options(&copts, C.GIT_PUSH_OPTIONS_VERSION)
|
C.git_push_init_options(&copts, C.GIT_PUSH_OPTIONS_VERSION)
|
||||||
if opts != nil {
|
if opts != nil {
|
||||||
copts.version = C.uint(opts.Version)
|
|
||||||
copts.pb_parallelism = C.uint(opts.PbParallelism)
|
copts.pb_parallelism = C.uint(opts.PbParallelism)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -456,7 +456,7 @@ func (v *Repository) TreeBuilder() (*TreeBuilder, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if ret := C.git_treebuilder_create(&bld.ptr, v.ptr, nil); ret < 0 {
|
if ret := C.git_treebuilder_new(&bld.ptr, v.ptr, nil); ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
||||||
|
@ -471,7 +471,7 @@ func (v *Repository) TreeBuilderFromTree(tree *Tree) (*TreeBuilder, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if ret := C.git_treebuilder_create(&bld.ptr, v.ptr, tree.cast_ptr); ret < 0 {
|
if ret := C.git_treebuilder_new(&bld.ptr, v.ptr, tree.cast_ptr); ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
runtime.SetFinalizer(bld, (*TreeBuilder).Free)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 247b3f4ee5d08ee5f5f88eb1c0f6ed03cbd21fc9
|
Subproject commit 55d9c29aa0c69cdd766c5100fc012d8e0b486e23
|
20
wrapper.c
20
wrapper.c
|
@ -1,9 +1,7 @@
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
#include "git2.h"
|
#include <git2.h>
|
||||||
#include "git2/sys/odb_backend.h"
|
#include <git2/sys/odb_backend.h>
|
||||||
#include "git2/sys/refdb_backend.h"
|
#include <git2/sys/refdb_backend.h>
|
||||||
#include "git2/submodule.h"
|
|
||||||
#include "git2/pack.h"
|
|
||||||
|
|
||||||
typedef int (*gogit_submodule_cbk)(git_submodule *sm, const char *name, void *payload);
|
typedef int (*gogit_submodule_cbk)(git_submodule *sm, const char *name, void *payload);
|
||||||
|
|
||||||
|
@ -84,18 +82,6 @@ void _go_git_setup_callbacks(git_remote_callbacks *callbacks) {
|
||||||
callbacks->push_update_reference = (push_update_reference_cb) pushUpdateReferenceCallback;
|
callbacks->push_update_reference = (push_update_reference_cb) pushUpdateReferenceCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*status_foreach_cb)(const char *ref, const char *msg, void *data);
|
|
||||||
|
|
||||||
int _go_git_push_status_foreach(git_push *push, void *data)
|
|
||||||
{
|
|
||||||
return git_push_status_foreach(push, (status_foreach_cb)statusForeach, 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, pushStructTransferProgress, transfer_progress_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
int _go_blob_chunk_cb(char *buffer, size_t maxLen, void *payload)
|
int _go_blob_chunk_cb(char *buffer, size_t maxLen, void *payload)
|
||||||
{
|
{
|
||||||
return blobChunkCb(buffer, maxLen, payload);
|
return blobChunkCb(buffer, maxLen, payload);
|
||||||
|
|
Loading…
Reference in New Issue