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 /merge.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 'merge.go')
| -rw-r--r-- | merge.go | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -172,21 +172,20 @@ func DefaultMergeOptions() (MergeOptions, error) { return mergeOptionsFromC(&opts), nil } -func (mo *MergeOptions) toC() *C.git_merge_options { - if mo == nil { +func populateMergeOptions(copts *C.git_merge_options, opts *MergeOptions) *C.git_merge_options { + C.git_merge_options_init(copts, C.GIT_MERGE_OPTIONS_VERSION) + if opts == nil { return nil } - return &C.git_merge_options{ - version: C.uint(mo.Version), - flags: C.uint32_t(mo.TreeFlags), - rename_threshold: C.uint(mo.RenameThreshold), - target_limit: C.uint(mo.TargetLimit), - recursion_limit: C.uint(mo.RecursionLimit), - file_favor: C.git_merge_file_favor_t(mo.FileFavor), - } + copts.flags = C.uint32_t(opts.TreeFlags) + copts.rename_threshold = C.uint(opts.RenameThreshold) + copts.target_limit = C.uint(opts.TargetLimit) + copts.recursion_limit = C.uint(opts.RecursionLimit) + copts.file_favor = C.git_merge_file_favor_t(opts.FileFavor) + return copts } -func freeMergeOptions(opts *C.git_merge_options) { +func freeMergeOptions(copts *C.git_merge_options) { } type MergeFileFavor int @@ -203,9 +202,9 @@ func (r *Repository) Merge(theirHeads []*AnnotatedCommit, mergeOptions *MergeOpt defer runtime.UnlockOSThread() var err error - cMergeOpts := mergeOptions.toC() + cMergeOpts := populateMergeOptions(&C.git_merge_options{}, mergeOptions) defer freeMergeOptions(cMergeOpts) - cCheckoutOptions := checkoutOptions.toC(&err) + cCheckoutOptions := populateCheckoutOptions(&C.git_checkout_options{}, checkoutOptions, &err) defer freeCheckoutOptions(cCheckoutOptions) gmerge_head_array := make([]*C.git_annotated_commit, len(theirHeads)) @@ -269,7 +268,7 @@ func (r *Repository) MergeCommits(ours *Commit, theirs *Commit, options *MergeOp runtime.LockOSThread() defer runtime.UnlockOSThread() - copts := options.toC() + copts := populateMergeOptions(&C.git_merge_options{}, options) defer freeMergeOptions(copts) var ptr *C.git_index @@ -287,7 +286,7 @@ func (r *Repository) MergeTrees(ancestor *Tree, ours *Tree, theirs *Tree, option runtime.LockOSThread() defer runtime.UnlockOSThread() - copts := options.toC() + copts := populateMergeOptions(&C.git_merge_options{}, options) defer freeMergeOptions(copts) var ancestor_ptr *C.git_tree @@ -446,22 +445,28 @@ func mergeFileOptionsFromC(c C.git_merge_file_options) MergeFileOptions { } } -func populateCMergeFileOptions(c *C.git_merge_file_options, options MergeFileOptions) { - c.ancestor_label = C.CString(options.AncestorLabel) - c.our_label = C.CString(options.OurLabel) - c.their_label = C.CString(options.TheirLabel) - c.favor = C.git_merge_file_favor_t(options.Favor) - c.flags = C.uint32_t(options.Flags) - c.marker_size = C.ushort(options.MarkerSize) +func populateMergeFileOptions(copts *C.git_merge_file_options, opts *MergeFileOptions) *C.git_merge_file_options { + C.git_merge_file_options_init(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION) + if opts == nil { + return nil + } + + copts.ancestor_label = C.CString(opts.AncestorLabel) + copts.our_label = C.CString(opts.OurLabel) + copts.their_label = C.CString(opts.TheirLabel) + copts.favor = C.git_merge_file_favor_t(opts.Favor) + copts.flags = C.uint32_t(opts.Flags) + copts.marker_size = C.ushort(opts.MarkerSize) + return copts } -func freeCMergeFileOptions(c *C.git_merge_file_options) { - if c == nil { +func freeMergeFileOptions(copts *C.git_merge_file_options) { + if copts == nil { return } - C.free(unsafe.Pointer(c.ancestor_label)) - C.free(unsafe.Pointer(c.our_label)) - C.free(unsafe.Pointer(c.their_label)) + C.free(unsafe.Pointer(copts.ancestor_label)) + C.free(unsafe.Pointer(copts.our_label)) + C.free(unsafe.Pointer(copts.their_label)) } func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInput, options *MergeFileOptions) (*MergeFileResult, error) { @@ -494,8 +499,8 @@ func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInp if ecode < 0 { return nil, MakeGitError(ecode) } - populateCMergeFileOptions(copts, *options) - defer freeCMergeFileOptions(copts) + populateMergeFileOptions(copts, options) + defer freeMergeFileOptions(copts) } runtime.LockOSThread() |
