Skip to content

Commit 717ea79

Browse files
committed
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.
1 parent 3496e60 commit 717ea79

File tree

8 files changed

+28
-34
lines changed

8 files changed

+28
-34
lines changed

cherrypick.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ import (
99
)
1010

1111
type CherrypickOptions struct {
12-
Version uint
13-
Mainline uint
14-
MergeOpts MergeOptions
15-
CheckoutOpts CheckoutOptions
12+
Mainline uint
13+
MergeOptions MergeOptions
14+
CheckoutOptions CheckoutOptions
1615
}
1716

1817
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
1918
opts := CherrypickOptions{
20-
Version: uint(c.version),
21-
Mainline: uint(c.mainline),
22-
MergeOpts: mergeOptionsFromC(&c.merge_opts),
23-
CheckoutOpts: checkoutOptionsFromC(&c.checkout_opts),
19+
Mainline: uint(c.mainline),
20+
MergeOptions: mergeOptionsFromC(&c.merge_opts),
21+
CheckoutOptions: checkoutOptionsFromC(&c.checkout_opts),
2422
}
2523
return opts
2624
}
@@ -31,8 +29,8 @@ func populateCherrypickOptions(copts *C.git_cherrypick_options, opts *Cherrypick
3129
return nil
3230
}
3331
copts.mainline = C.uint(opts.Mainline)
34-
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
35-
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
32+
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
33+
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
3634
return copts
3735
}
3836

@@ -82,7 +80,7 @@ func (r *Repository) CherrypickCommit(pick, our *Commit, opts CherrypickOptions)
8280
runtime.LockOSThread()
8381
defer runtime.UnlockOSThread()
8482

85-
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOpts)
83+
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOptions)
8684
defer freeMergeOptions(cOpts)
8785

8886
var ptr *C.git_index

clone.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, error)
1515

1616
type CloneOptions struct {
17-
*CheckoutOpts
18-
*FetchOptions
17+
CheckoutOptions CheckoutOptions
18+
FetchOptions FetchOptions
1919
Bare bool
2020
CheckoutBranch string
2121
RemoteCreateCallback RemoteCreateCallback
@@ -100,8 +100,8 @@ func populateCloneOptions(copts *C.git_clone_options, opts *CloneOptions, errorT
100100
if opts == nil {
101101
return nil
102102
}
103-
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
104-
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget)
103+
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
104+
populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
105105
copts.bare = cbool(opts.Bare)
106106

107107
if opts.RemoteCreateCallback != nil {

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func NewOid(s string) (*Oid, error) {
227227
}
228228

229229
if len(slice) != 20 {
230-
return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric}
230+
return nil, &GitError{"invalid oid", ErrorClassNone, ErrorCodeGeneric}
231231
}
232232

233233
copy(o[:], slice[:20])

merge.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ const (
138138
)
139139

140140
type MergeOptions struct {
141-
Version uint
142141
TreeFlags MergeTreeFlag
143142

144143
RenameThreshold uint
@@ -151,7 +150,6 @@ type MergeOptions struct {
151150

152151
func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions {
153152
return MergeOptions{
154-
Version: uint(opts.version),
155153
TreeFlags: MergeTreeFlag(opts.flags),
156154
RenameThreshold: uint(opts.rename_threshold),
157155
TargetLimit: uint(opts.target_limit),

rebase.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func commitSigningCallback(errorMessage **C.char, _signature *C.git_buf, _signat
130130

131131
// RebaseOptions are used to tell the rebase machinery how to operate
132132
type RebaseOptions struct {
133-
Version uint
134133
Quiet int
135134
InMemory int
136135
RewriteNotesRef string
@@ -160,7 +159,6 @@ func DefaultRebaseOptions() (RebaseOptions, error) {
160159

161160
func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
162161
return RebaseOptions{
163-
Version: uint(opts.version),
164162
Quiet: int(opts.quiet),
165163
InMemory: int(opts.inmemory),
166164
RewriteNotesRef: C.GoString(opts.rewrite_notes_ref),

revert.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010

1111
// RevertOptions contains options for performing a revert
1212
type RevertOptions struct {
13-
Mainline uint
14-
MergeOpts MergeOptions
15-
CheckoutOpts CheckoutOptions
13+
Mainline uint
14+
MergeOptions MergeOptions
15+
CheckoutOptions CheckoutOptions
1616
}
1717

1818
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
2121
return nil
2222
}
2323
copts.mainline = C.uint(opts.Mainline)
24-
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
25-
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
24+
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
25+
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
2626
return copts
2727
}
2828

2929
func revertOptionsFromC(copts *C.git_revert_options) RevertOptions {
3030
return RevertOptions{
31-
Mainline: uint(copts.mainline),
32-
MergeOpts: mergeOptionsFromC(&copts.merge_opts),
33-
CheckoutOpts: checkoutOptionsFromC(&copts.checkout_opts),
31+
Mainline: uint(copts.mainline),
32+
MergeOptions: mergeOptionsFromC(&copts.merge_opts),
33+
CheckoutOptions: checkoutOptionsFromC(&copts.checkout_opts),
3434
}
3535
}
3636

revert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func TestRevertCommit(t *testing.T) {
6060
revertOptions, err := DefaultRevertOptions()
6161
checkFatal(t, err)
6262

63-
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOpts)
63+
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOptions)
6464
checkFatal(t, err)
6565
defer index.Free()
6666

67-
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOpts)
67+
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOptions)
6868
checkFatal(t, err)
6969

7070
actualReadmeContents := readReadme(t, repo)

submodule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
// SubmoduleUpdateOptions
1616
type SubmoduleUpdateOptions struct {
17-
*CheckoutOpts
18-
*FetchOptions
17+
CheckoutOptions CheckoutOptions
18+
FetchOptions FetchOptions
1919
}
2020

2121
// Submodule
@@ -390,8 +390,8 @@ func populateSubmoduleUpdateOptions(copts *C.git_submodule_update_options, opts
390390
return nil
391391
}
392392

393-
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
394-
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget)
393+
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
394+
populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
395395

396396
return copts
397397
}

0 commit comments

Comments
 (0)