diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-03-11 03:27:35 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-03-11 03:27:35 +0100 |
| commit | b09c6d8bbe874d6a08e0c91ad3f11bceb74414b2 (patch) | |
| tree | 49b9a36877efc666e9868977d220bba5cca02ea0 | |
| parent | b5b0f3f50e151ef67f8cd7b10044c81920093a81 (diff) | |
Move checkout functions options more in line with the library
Afjust Checkout -> CheckoutHead and pass nil if the options structure is
nil so as not to overide the library's decisions.
| -rw-r--r-- | checkout.go | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/checkout.go b/checkout.go index 0f112a7..5753b09 100644 --- a/checkout.go +++ b/checkout.go @@ -38,28 +38,34 @@ type CheckoutOpts struct { FileOpenFlags int // Default is O_CREAT | O_TRUNC | O_WRONLY } -// Convert the CheckoutOpts struct to the corresponding C-struct -func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) { - C.git_checkout_init_opts(ptr, 1) +// Convert the CheckoutOpts struct to the corresponding +// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order +// to help with what to pass. +func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options { if opts == nil { - return + return nil } + + C.git_checkout_init_opts(ptr, 1) ptr.checkout_strategy = C.uint(opts.Strategy) ptr.disable_filters = cbool(opts.DisableFilters) ptr.dir_mode = C.uint(opts.DirMode.Perm()) ptr.file_mode = C.uint(opts.FileMode.Perm()) + + return ptr } // Updates files in the index and the working tree to match the content of -// the commit pointed at by HEAD. -func (v *Repository) Checkout(opts *CheckoutOpts) error { +// the commit pointed at by HEAD. opts may be nil. +func (v *Repository) CheckoutHead(opts *CheckoutOpts) error { var copts C.git_checkout_options - populateCheckoutOpts(&copts, opts) + + ptr := populateCheckoutOpts(&copts, opts) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_checkout_head(v.ptr, &copts) + ret := C.git_checkout_head(v.ptr, ptr) if ret < 0 { return MakeGitError(ret) } @@ -67,15 +73,16 @@ func (v *Repository) Checkout(opts *CheckoutOpts) error { return nil } -// Updates files in the working tree to match the content of the index. +// Updates files in the working tree to match the content of the given +// index. opts may be nil. func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error { var copts C.git_checkout_options - populateCheckoutOpts(&copts, opts) + ptr := populateCheckoutOpts(&copts, opts) runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_checkout_index(v.ptr, index.ptr, &copts) + ret := C.git_checkout_index(v.ptr, index.ptr, ptr) if ret < 0 { return MakeGitError(ret) } |
