@@ -87,13 +87,6 @@ func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOptions {
87
87
return opts
88
88
}
89
89
90
- func (opts * CheckoutOptions ) toC (errorTarget * error ) * C.git_checkout_options {
91
- if opts == nil {
92
- return nil
93
- }
94
- return populateCheckoutOptions (& C.git_checkout_options {}, opts , errorTarget )
95
- }
96
-
97
90
type checkoutCallbackData struct {
98
91
options * CheckoutOptions
99
92
errorTarget * error
@@ -144,61 +137,61 @@ func checkoutProgressCallback(
144
137
data .options .ProgressCallback (C .GoString (path ), uint (completed_steps ), uint (total_steps ))
145
138
}
146
139
147
- // Convert the CheckoutOptions struct to the corresponding
148
- // C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
149
- // to help with what to pass.
150
- func populateCheckoutOptions (ptr * C.git_checkout_options , opts * CheckoutOptions , errorTarget * error ) * C.git_checkout_options {
140
+ // populateCheckoutOptions populates the provided C-struct with the contents of
141
+ // the provided CheckoutOptions struct. Returns copts, or nil if opts is nil,
142
+ // in order to help with what to pass.
143
+ func populateCheckoutOptions (copts * C.git_checkout_options , opts * CheckoutOptions , errorTarget * error ) * C.git_checkout_options {
144
+ C .git_checkout_init_options (copts , C .GIT_CHECKOUT_OPTIONS_VERSION )
151
145
if opts == nil {
152
146
return nil
153
147
}
154
148
155
- C .git_checkout_init_options (ptr , 1 )
156
- ptr .checkout_strategy = C .uint (opts .Strategy )
157
- ptr .disable_filters = cbool (opts .DisableFilters )
158
- ptr .dir_mode = C .uint (opts .DirMode .Perm ())
159
- ptr .file_mode = C .uint (opts .FileMode .Perm ())
160
- ptr .notify_flags = C .uint (opts .NotifyFlags )
149
+ copts .checkout_strategy = C .uint (opts .Strategy )
150
+ copts .disable_filters = cbool (opts .DisableFilters )
151
+ copts .dir_mode = C .uint (opts .DirMode .Perm ())
152
+ copts .file_mode = C .uint (opts .FileMode .Perm ())
153
+ copts .notify_flags = C .uint (opts .NotifyFlags )
161
154
if opts .NotifyCallback != nil || opts .ProgressCallback != nil {
162
- C ._go_git_populate_checkout_callbacks (ptr )
155
+ C ._go_git_populate_checkout_callbacks (copts )
163
156
data := & checkoutCallbackData {
164
157
options : opts ,
165
158
errorTarget : errorTarget ,
166
159
}
167
160
payload := pointerHandles .Track (data )
168
161
if opts .NotifyCallback != nil {
169
- ptr .notify_payload = payload
162
+ copts .notify_payload = payload
170
163
}
171
164
if opts .ProgressCallback != nil {
172
- ptr .progress_payload = payload
165
+ copts .progress_payload = payload
173
166
}
174
167
}
175
168
if opts .TargetDirectory != "" {
176
- ptr .target_directory = C .CString (opts .TargetDirectory )
169
+ copts .target_directory = C .CString (opts .TargetDirectory )
177
170
}
178
171
if len (opts .Paths ) > 0 {
179
- ptr .paths .strings = makeCStringsFromStrings (opts .Paths )
180
- ptr .paths .count = C .size_t (len (opts .Paths ))
172
+ copts .paths .strings = makeCStringsFromStrings (opts .Paths )
173
+ copts .paths .count = C .size_t (len (opts .Paths ))
181
174
}
182
175
183
176
if opts .Baseline != nil {
184
- ptr .baseline = opts .Baseline .cast_ptr
177
+ copts .baseline = opts .Baseline .cast_ptr
185
178
}
186
179
187
- return ptr
180
+ return copts
188
181
}
189
182
190
- func freeCheckoutOptions (ptr * C.git_checkout_options ) {
191
- if ptr == nil {
183
+ func freeCheckoutOptions (copts * C.git_checkout_options ) {
184
+ if copts == nil {
192
185
return
193
186
}
194
- C .free (unsafe .Pointer (ptr .target_directory ))
195
- if ptr .paths .count > 0 {
196
- freeStrarray (& ptr .paths )
187
+ C .free (unsafe .Pointer (copts .target_directory ))
188
+ if copts .paths .count > 0 {
189
+ freeStrarray (& copts .paths )
197
190
}
198
- if ptr .notify_payload != nil {
199
- pointerHandles .Untrack (ptr .notify_payload )
200
- } else if ptr .progress_payload != nil {
201
- pointerHandles .Untrack (ptr .progress_payload )
191
+ if copts .notify_payload != nil {
192
+ pointerHandles .Untrack (copts .notify_payload )
193
+ } else if copts .progress_payload != nil {
194
+ pointerHandles .Untrack (copts .progress_payload )
202
195
}
203
196
}
204
197
@@ -209,7 +202,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOptions) error {
209
202
defer runtime .UnlockOSThread ()
210
203
211
204
var err error
212
- cOpts := opts . toC ( & err )
205
+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
213
206
defer freeCheckoutOptions (cOpts )
214
207
215
208
ret := C .git_checkout_head (v .ptr , cOpts )
@@ -238,7 +231,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOptions) error {
238
231
defer runtime .UnlockOSThread ()
239
232
240
233
var err error
241
- cOpts := opts . toC ( & err )
234
+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
242
235
defer freeCheckoutOptions (cOpts )
243
236
244
237
ret := C .git_checkout_index (v .ptr , iptr , cOpts )
@@ -258,7 +251,7 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOptions) error {
258
251
defer runtime .UnlockOSThread ()
259
252
260
253
var err error
261
- cOpts := opts . toC ( & err )
254
+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
262
255
defer freeCheckoutOptions (cOpts )
263
256
264
257
ret := C .git_checkout_tree (v .ptr , tree .ptr , cOpts )
0 commit comments