@@ -87,13 +87,6 @@ func checkoutOptionsFromC(c *C.git_checkout_options) CheckoutOptions {
8787 return opts
8888}
8989
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-
9790type checkoutCallbackData struct {
9891 options * CheckoutOptions
9992 errorTarget * error
@@ -144,61 +137,61 @@ func checkoutProgressCallback(
144137 data .options .ProgressCallback (C .GoString (path ), uint (completed_steps ), uint (total_steps ))
145138}
146139
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_options_init (copts , C .GIT_CHECKOUT_OPTIONS_VERSION )
151145 if opts == nil {
152146 return nil
153147 }
154148
155- C .git_checkout_options_init (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 )
161154 if opts .NotifyCallback != nil || opts .ProgressCallback != nil {
162- C ._go_git_populate_checkout_callbacks (ptr )
155+ C ._go_git_populate_checkout_callbacks (copts )
163156 data := & checkoutCallbackData {
164157 options : opts ,
165158 errorTarget : errorTarget ,
166159 }
167160 payload := pointerHandles .Track (data )
168161 if opts .NotifyCallback != nil {
169- ptr .notify_payload = payload
162+ copts .notify_payload = payload
170163 }
171164 if opts .ProgressCallback != nil {
172- ptr .progress_payload = payload
165+ copts .progress_payload = payload
173166 }
174167 }
175168 if opts .TargetDirectory != "" {
176- ptr .target_directory = C .CString (opts .TargetDirectory )
169+ copts .target_directory = C .CString (opts .TargetDirectory )
177170 }
178171 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 ))
181174 }
182175
183176 if opts .Baseline != nil {
184- ptr .baseline = opts .Baseline .cast_ptr
177+ copts .baseline = opts .Baseline .cast_ptr
185178 }
186179
187- return ptr
180+ return copts
188181}
189182
190- func freeCheckoutOptions (ptr * C.git_checkout_options ) {
191- if ptr == nil {
183+ func freeCheckoutOptions (copts * C.git_checkout_options ) {
184+ if copts == nil {
192185 return
193186 }
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 )
197190 }
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 )
202195 }
203196}
204197
@@ -209,7 +202,7 @@ func (v *Repository) CheckoutHead(opts *CheckoutOptions) error {
209202 defer runtime .UnlockOSThread ()
210203
211204 var err error
212- cOpts := opts . toC ( & err )
205+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
213206 defer freeCheckoutOptions (cOpts )
214207
215208 ret := C .git_checkout_head (v .ptr , cOpts )
@@ -238,7 +231,7 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOptions) error {
238231 defer runtime .UnlockOSThread ()
239232
240233 var err error
241- cOpts := opts . toC ( & err )
234+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
242235 defer freeCheckoutOptions (cOpts )
243236
244237 ret := C .git_checkout_index (v .ptr , iptr , cOpts )
@@ -258,7 +251,7 @@ func (v *Repository) CheckoutTree(tree *Tree, opts *CheckoutOptions) error {
258251 defer runtime .UnlockOSThread ()
259252
260253 var err error
261- cOpts := opts . toC ( & err )
254+ cOpts := populateCheckoutOptions ( & C. git_checkout_options {}, opts , & err )
262255 defer freeCheckoutOptions (cOpts )
263256
264257 ret := C .git_checkout_tree (v .ptr , tree .ptr , cOpts )
0 commit comments