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 /stash.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 'stash.go')
| -rw-r--r-- | stash.go | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -161,34 +161,32 @@ func DefaultStashApplyOptions() (StashApplyOptions, error) { }, nil } -func (opts *StashApplyOptions) toC(errorTarget *error) *C.git_stash_apply_options { +func populateStashApplyOptions(copts *C.git_stash_apply_options, opts *StashApplyOptions, errorTarget *error) *C.git_stash_apply_options { + C.git_stash_apply_options_init(copts, C.GIT_STASH_APPLY_OPTIONS_VERSION) if opts == nil { return nil } - optsC := &C.git_stash_apply_options{ - version: C.GIT_STASH_APPLY_OPTIONS_VERSION, - flags: C.uint32_t(opts.Flags), - } - populateCheckoutOptions(&optsC.checkout_options, &opts.CheckoutOptions, errorTarget) + copts.flags = C.uint32_t(opts.Flags) + populateCheckoutOptions(&copts.checkout_options, &opts.CheckoutOptions, errorTarget) if opts.ProgressCallback != nil { progressData := &stashApplyProgressCallbackData{ callback: opts.ProgressCallback, errorTarget: errorTarget, } - C._go_git_populate_stash_apply_callbacks(optsC) - optsC.progress_payload = pointerHandles.Track(progressData) + C._go_git_populate_stash_apply_callbacks(copts) + copts.progress_payload = pointerHandles.Track(progressData) } - return optsC + return copts } -func freeStashApplyOptions(optsC *C.git_stash_apply_options) { - if optsC == nil { +func freeStashApplyOptions(copts *C.git_stash_apply_options) { + if copts == nil { return } - if optsC.progress_payload != nil { - pointerHandles.Untrack(optsC.progress_payload) + if copts.progress_payload != nil { + pointerHandles.Untrack(copts.progress_payload) } - freeCheckoutOptions(&optsC.checkout_options) + freeCheckoutOptions(&copts.checkout_options) } // Apply applies a single stashed state from the stash list. @@ -217,7 +215,7 @@ func freeStashApplyOptions(optsC *C.git_stash_apply_options) { // Error codes can be interogated with IsErrorCode(err, ErrorCodeNotFound). func (c *StashCollection) Apply(index int, opts StashApplyOptions) error { var err error - optsC := opts.toC(&err) + optsC := populateStashApplyOptions(&C.git_stash_apply_options{}, &opts, &err) defer freeStashApplyOptions(optsC) runtime.LockOSThread() @@ -320,7 +318,7 @@ func (c *StashCollection) Drop(index int) error { // state for the given index. func (c *StashCollection) Pop(index int, opts StashApplyOptions) error { var err error - optsC := opts.toC(&err) + optsC := populateStashApplyOptions(&C.git_stash_apply_options{}, &opts, &err) defer freeStashApplyOptions(optsC) runtime.LockOSThread() |
