transfer progress
This commit is contained in:
parent
f33c856845
commit
09f2361ba6
61
remote.go
61
remote.go
|
@ -30,6 +30,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProgressCb func([]byte) int
|
type ProgressCb func([]byte) int
|
||||||
|
type TransferProgressCb func(*TransferProgress) int
|
||||||
type UpdateTipsCb func(string, *Oid, *Oid) int
|
type UpdateTipsCb func(string, *Oid, *Oid) int
|
||||||
|
|
||||||
type Remote struct {
|
type Remote struct {
|
||||||
|
@ -38,6 +39,7 @@ type Remote struct {
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
Progress ProgressCb
|
Progress ProgressCb
|
||||||
|
TransferProgress TransferProgressCb
|
||||||
UpdateTips UpdateTipsCb
|
UpdateTips UpdateTipsCb
|
||||||
|
|
||||||
ptr *C.git_remote
|
ptr *C.git_remote
|
||||||
|
@ -98,6 +100,24 @@ func (r *Remote) Ls() ([]*RemoteHead, error) {
|
||||||
return data.slice, nil
|
return data.slice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Remote) Download() error {
|
||||||
|
ret := C.git_remote_download(r.ptr)
|
||||||
|
if ret < 0 {
|
||||||
|
LastError()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Remote) Fetch() error {
|
||||||
|
ret := C.git_remote_fetch(r.ptr)
|
||||||
|
if ret < 0 {
|
||||||
|
LastError()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
//export remoteProgress
|
//export remoteProgress
|
||||||
func remoteProgress(str *C.char, length C.int, data unsafe.Pointer) int {
|
func remoteProgress(str *C.char, length C.int, data unsafe.Pointer) int {
|
||||||
remote := (*Remote)(data)
|
remote := (*Remote)(data)
|
||||||
|
@ -108,24 +128,27 @@ func remoteProgress(str *C.char, length C.int, data unsafe.Pointer) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//export remoteUpdateTips
|
//export remoteTransferProgress
|
||||||
func remoteUpdateTips(str *C.char, a, b *C.git_oid, data unsafe.Pointer) int {
|
func remoteTransferProgress(ptr *C.git_transfer_progress, data unsafe.Pointer) int {
|
||||||
remote := (*Remote)(data)
|
remote := (*Remote)(data)
|
||||||
if remote.UpdateTips != nil {
|
if remote.TransferProgress != nil {
|
||||||
goa, gob := newOidFromC(a), newOidFromC(b)
|
return remote.TransferProgress(newTransferProgressFromC(ptr))
|
||||||
return remote.UpdateTips(C.GoString(str), goa, gob)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Remote) Download() (error) {
|
//export remoteUpdateTips
|
||||||
ret := C.git_remote_download(r.ptr)
|
func remoteUpdateTips(str *C.char, a, b *C.git_oid, data unsafe.Pointer) int {
|
||||||
if ret < 0 {
|
remote := (*Remote)(data)
|
||||||
LastError()
|
if remote.UpdateTips != nil {
|
||||||
|
var goa, gob Oid
|
||||||
|
CopyOid(&goa, a)
|
||||||
|
CopyOid(&gob, b)
|
||||||
|
return remote.UpdateTips(C.GoString(str), &goa, &gob)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type headlistData struct {
|
type headlistData struct {
|
||||||
|
@ -162,6 +185,24 @@ func newRemoteFromC(ptr *C.git_remote) *Remote {
|
||||||
return remote
|
return remote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transfer progress
|
||||||
|
|
||||||
|
type TransferProgress struct {
|
||||||
|
TotalObjects uint
|
||||||
|
IndexedObjects uint
|
||||||
|
ReceivedObjects uint
|
||||||
|
ReceivedBytes uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTransferProgressFromC(ptr *C.git_transfer_progress) *TransferProgress {
|
||||||
|
return &TransferProgress{
|
||||||
|
TotalObjects: uint(ptr.total_objects),
|
||||||
|
IndexedObjects: uint(ptr.indexed_objects),
|
||||||
|
ReceivedObjects: uint(ptr.received_objects),
|
||||||
|
ReceivedBytes: uint64(ptr.received_bytes),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// remote heads
|
// remote heads
|
||||||
|
|
||||||
// RemoteHead represents a reference available in the remote repository.
|
// RemoteHead represents a reference available in the remote repository.
|
||||||
|
|
|
@ -36,6 +36,7 @@ int _go_git_remote_set_callbacks(git_remote *remote, void *payload)
|
||||||
git_remote_callbacks cbs = GIT_REMOTE_CALLBACKS_INIT;
|
git_remote_callbacks cbs = GIT_REMOTE_CALLBACKS_INIT;
|
||||||
|
|
||||||
cbs.progress = remoteProgress;
|
cbs.progress = remoteProgress;
|
||||||
|
cbs.transfer_progress = remoteTransferProgress;
|
||||||
cbs.update_tips = remoteUpdateTips;
|
cbs.update_tips = remoteUpdateTips;
|
||||||
cbs.payload = payload;
|
cbs.payload = payload;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue