Make all Options objects consistent

This change makes all Options objects have child Option fields as values
(instead of pointers) to mirror the libgit2 interface. It also names
them Options instead of Opts to match the current libgit2 nomenclature
and removes the Version fields.
This commit is contained in:
lhchavez 2020-12-04 19:54:26 -08:00
parent 5def02a589
commit b78bde3d74
8 changed files with 28 additions and 34 deletions

View File

@ -9,18 +9,16 @@ import (
) )
type CherrypickOptions struct { type CherrypickOptions struct {
Version uint Mainline uint
Mainline uint MergeOptions MergeOptions
MergeOpts MergeOptions CheckoutOptions CheckoutOptions
CheckoutOpts CheckoutOptions
} }
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions { func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
opts := CherrypickOptions{ opts := CherrypickOptions{
Version: uint(c.version), Mainline: uint(c.mainline),
Mainline: uint(c.mainline), MergeOptions: mergeOptionsFromC(&c.merge_opts),
MergeOpts: mergeOptionsFromC(&c.merge_opts), CheckoutOptions: checkoutOptionsFromC(&c.checkout_opts),
CheckoutOpts: checkoutOptionsFromC(&c.checkout_opts),
} }
return opts return opts
} }
@ -31,8 +29,8 @@ func populateCherrypickOptions(copts *C.git_cherrypick_options, opts *Cherrypick
return nil return nil
} }
copts.mainline = C.uint(opts.Mainline) copts.mainline = C.uint(opts.Mainline)
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts) populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget) populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
return copts return copts
} }
@ -82,7 +80,7 @@ func (r *Repository) CherrypickCommit(pick, our *Commit, opts CherrypickOptions)
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOpts) cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOptions)
defer freeMergeOptions(cOpts) defer freeMergeOptions(cOpts)
var ptr *C.git_index var ptr *C.git_index

View File

@ -14,8 +14,8 @@ import (
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, error) type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, error)
type CloneOptions struct { type CloneOptions struct {
*CheckoutOpts CheckoutOptions CheckoutOptions
*FetchOptions FetchOptions FetchOptions
Bare bool Bare bool
CheckoutBranch string CheckoutBranch string
RemoteCreateCallback RemoteCreateCallback RemoteCreateCallback RemoteCreateCallback
@ -100,8 +100,8 @@ func populateCloneOptions(copts *C.git_clone_options, opts *CloneOptions, errorT
if opts == nil { if opts == nil {
return nil return nil
} }
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget) populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget) populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
copts.bare = cbool(opts.Bare) copts.bare = cbool(opts.Bare)
if opts.RemoteCreateCallback != nil { if opts.RemoteCreateCallback != nil {

2
git.go
View File

@ -227,7 +227,7 @@ func NewOid(s string) (*Oid, error) {
} }
if len(slice) != 20 { if len(slice) != 20 {
return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric} return nil, &GitError{"invalid oid", ErrorClassNone, ErrorCodeGeneric}
} }
copy(o[:], slice[:20]) copy(o[:], slice[:20])

View File

@ -138,7 +138,6 @@ const (
) )
type MergeOptions struct { type MergeOptions struct {
Version uint
TreeFlags MergeTreeFlag TreeFlags MergeTreeFlag
RenameThreshold uint RenameThreshold uint
@ -151,7 +150,6 @@ type MergeOptions struct {
func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions { func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions {
return MergeOptions{ return MergeOptions{
Version: uint(opts.version),
TreeFlags: MergeTreeFlag(opts.flags), TreeFlags: MergeTreeFlag(opts.flags),
RenameThreshold: uint(opts.rename_threshold), RenameThreshold: uint(opts.rename_threshold),
TargetLimit: uint(opts.target_limit), TargetLimit: uint(opts.target_limit),

View File

@ -130,7 +130,6 @@ func commitSigningCallback(errorMessage **C.char, _signature *C.git_buf, _signat
// RebaseOptions are used to tell the rebase machinery how to operate // RebaseOptions are used to tell the rebase machinery how to operate
type RebaseOptions struct { type RebaseOptions struct {
Version uint
Quiet int Quiet int
InMemory int InMemory int
RewriteNotesRef string RewriteNotesRef string
@ -160,7 +159,6 @@ func DefaultRebaseOptions() (RebaseOptions, error) {
func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions { func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
return RebaseOptions{ return RebaseOptions{
Version: uint(opts.version),
Quiet: int(opts.quiet), Quiet: int(opts.quiet),
InMemory: int(opts.inmemory), InMemory: int(opts.inmemory),
RewriteNotesRef: C.GoString(opts.rewrite_notes_ref), RewriteNotesRef: C.GoString(opts.rewrite_notes_ref),

View File

@ -10,9 +10,9 @@ import (
// RevertOptions contains options for performing a revert // RevertOptions contains options for performing a revert
type RevertOptions struct { type RevertOptions struct {
Mainline uint Mainline uint
MergeOpts MergeOptions MergeOptions MergeOptions
CheckoutOpts CheckoutOptions CheckoutOptions CheckoutOptions
} }
func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, errorTarget *error) *C.git_revert_options { func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, errorTarget *error) *C.git_revert_options {
@ -21,16 +21,16 @@ func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, err
return nil return nil
} }
copts.mainline = C.uint(opts.Mainline) copts.mainline = C.uint(opts.Mainline)
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts) populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget) populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
return copts return copts
} }
func revertOptionsFromC(copts *C.git_revert_options) RevertOptions { func revertOptionsFromC(copts *C.git_revert_options) RevertOptions {
return RevertOptions{ return RevertOptions{
Mainline: uint(copts.mainline), Mainline: uint(copts.mainline),
MergeOpts: mergeOptionsFromC(&copts.merge_opts), MergeOptions: mergeOptionsFromC(&copts.merge_opts),
CheckoutOpts: checkoutOptionsFromC(&copts.checkout_opts), CheckoutOptions: checkoutOptionsFromC(&copts.checkout_opts),
} }
} }

View File

@ -60,11 +60,11 @@ func TestRevertCommit(t *testing.T) {
revertOptions, err := DefaultRevertOptions() revertOptions, err := DefaultRevertOptions()
checkFatal(t, err) checkFatal(t, err)
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOpts) index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOptions)
checkFatal(t, err) checkFatal(t, err)
defer index.Free() defer index.Free()
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOpts) err = repo.CheckoutIndex(index, &revertOptions.CheckoutOptions)
checkFatal(t, err) checkFatal(t, err)
actualReadmeContents := readReadme(t, repo) actualReadmeContents := readReadme(t, repo)

View File

@ -14,8 +14,8 @@ import (
// SubmoduleUpdateOptions // SubmoduleUpdateOptions
type SubmoduleUpdateOptions struct { type SubmoduleUpdateOptions struct {
*CheckoutOpts CheckoutOptions CheckoutOptions
*FetchOptions FetchOptions FetchOptions
} }
// Submodule // Submodule
@ -390,8 +390,8 @@ func populateSubmoduleUpdateOptions(copts *C.git_submodule_update_options, opts
return nil return nil
} }
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget) populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget) populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
return copts return copts
} }