diff options
| author | lhchavez <[email protected]> | 2020-12-10 07:19:41 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-10 07:19:41 -0800 |
| commit | 10c67474a89c298172a6703b91980ea37c60d5e5 (patch) | |
| tree | 8b32fd2ce9540e01e90ddd09b59969d85832dc25 /odb.go | |
| parent | e28cce87c7551bffa1f4602ff492348f9a8cba60 (diff) | |
More callback refactoring (#713)
This change:
* Gets rid of the `.toC()` functions for Options objects, since they
were redundant with the `populateXxxOptions()`.
* Adds support for `errorTarget` to the `RemoteOptions`, since they are
used in the same stack for some functions (like `Fetch()`). Now for
those cases, the error returned by the callback will be preserved
as-is.
Diffstat (limited to 'odb.go')
| -rw-r--r-- | odb.go | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -291,18 +291,16 @@ func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, err // layer does not understand pack files, the objects will be stored in whatever // format the ODB layer uses. func (v *Odb) NewWritePack(callback TransferProgressCallback) (*OdbWritepack, error) { - writepack := new(OdbWritepack) - runtime.LockOSThread() defer runtime.UnlockOSThread() - writepack.callbacks.TransferProgressCallback = callback - writepack.callbacksHandle = pointerHandles.Track(&writepack.callbacks) + writepack := new(OdbWritepack) + populateRemoteCallbacks(&writepack.ccallbacks, &RemoteCallbacks{TransferProgressCallback: callback}, nil) - ret := C._go_git_odb_write_pack(&writepack.ptr, v.ptr, writepack.callbacksHandle) + ret := C._go_git_odb_write_pack(&writepack.ptr, v.ptr, writepack.ccallbacks.payload) runtime.KeepAlive(v) if ret < 0 { - pointerHandles.Untrack(writepack.callbacksHandle) + untrackCallbacksPayload(&writepack.ccallbacks) return nil, MakeGitError(ret) } @@ -442,10 +440,9 @@ func (stream *OdbWriteStream) Free() { // OdbWritepack is a stream to write a packfile to the ODB. type OdbWritepack struct { - ptr *C.git_odb_writepack - stats C.git_transfer_progress - callbacks RemoteCallbacks - callbacksHandle unsafe.Pointer + ptr *C.git_odb_writepack + stats C.git_transfer_progress + ccallbacks C.git_remote_callbacks } func (writepack *OdbWritepack) Write(data []byte) (int, error) { @@ -479,7 +476,7 @@ func (writepack *OdbWritepack) Commit() error { } func (writepack *OdbWritepack) Free() { - pointerHandles.Untrack(writepack.callbacksHandle) + untrackCallbacksPayload(&writepack.ccallbacks) runtime.SetFinalizer(writepack, nil) C._go_git_odb_writepack_free(writepack.ptr) } |
