From 42fce02197789a1577ff7130f7f46ce47e584aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 11 Mar 2014 03:09:48 +0100 Subject: [PATCH 1/4] Adjust to checkout_opts -> checkout_options --- checkout.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/checkout.go b/checkout.go index d3cd47b..5becd0e 100644 --- a/checkout.go +++ b/checkout.go @@ -2,8 +2,8 @@ package git /* #include -git_checkout_opts git_checkout_opts_init() { - git_checkout_opts ret = GIT_CHECKOUT_OPTS_INIT; +git_checkout_options git_checkout_opts_init() { + git_checkout_options ret = GIT_CHECKOUT_OPTIONS_INIT; return ret; } */ @@ -43,7 +43,7 @@ type CheckoutOpts struct { } // Convert the CheckoutOpts struct to the corresponding C-struct -func populateCheckoutOpts(ptr *C.git_checkout_opts, opts *CheckoutOpts) { +func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) { *ptr = C.git_checkout_opts_init() if opts == nil { return @@ -57,7 +57,7 @@ func populateCheckoutOpts(ptr *C.git_checkout_opts, opts *CheckoutOpts) { // 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 { - var copts C.git_checkout_opts + var copts C.git_checkout_options populateCheckoutOpts(&copts, opts) runtime.LockOSThread() @@ -73,7 +73,7 @@ func (v *Repository) Checkout(opts *CheckoutOpts) error { // Updates files in the working tree to match the content of the index. func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error { - var copts C.git_checkout_opts + var copts C.git_checkout_options populateCheckoutOpts(&copts, opts) runtime.LockOSThread() From b5b0f3f50e151ef67f8cd7b10044c81920093a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 11 Mar 2014 03:14:36 +0100 Subject: [PATCH 2/4] Remove custom checkout opts init function --- checkout.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/checkout.go b/checkout.go index 5becd0e..0f112a7 100644 --- a/checkout.go +++ b/checkout.go @@ -2,10 +2,6 @@ package git /* #include -git_checkout_options git_checkout_opts_init() { - git_checkout_options ret = GIT_CHECKOUT_OPTIONS_INIT; - return ret; -} */ import "C" import ( @@ -44,7 +40,7 @@ type CheckoutOpts struct { // Convert the CheckoutOpts struct to the corresponding C-struct func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) { - *ptr = C.git_checkout_opts_init() + C.git_checkout_init_opts(ptr, 1) if opts == nil { return } From b09c6d8bbe874d6a08e0c91ad3f11bceb74414b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 11 Mar 2014 03:27:35 +0100 Subject: [PATCH 3/4] 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. --- checkout.go | 29 ++++++++++++++++++----------- 1 file 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) } From 263884a908873803cb8a37f80ba89e7b98001f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 11 Mar 2014 03:30:56 +0100 Subject: [PATCH 4/4] CheckoutIndex: allow for index to be nil Allow for the index to be nil and pass that to the library to use the repository's index. --- checkout.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/checkout.go b/checkout.go index 5753b09..5b72b9a 100644 --- a/checkout.go +++ b/checkout.go @@ -74,15 +74,21 @@ func (v *Repository) CheckoutHead(opts *CheckoutOpts) error { } // Updates files in the working tree to match the content of the given -// index. opts may be nil. +// index. If index is nil, the repository's index will be used. opts +// may be nil. func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error { var copts C.git_checkout_options ptr := populateCheckoutOpts(&copts, opts) + var iptr *C.git_index = nil + if index != nil { + iptr = index.ptr + } + runtime.LockOSThread() defer runtime.UnlockOSThread() - ret := C.git_checkout_index(v.ptr, index.ptr, ptr) + ret := C.git_checkout_index(v.ptr, iptr, ptr) if ret < 0 { return MakeGitError(ret) }