Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/libgit2/git2go/cherrypick.go')
-rw-r--r--vendor/github.com/libgit2/git2go/cherrypick.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/libgit2/git2go/cherrypick.go b/vendor/github.com/libgit2/git2go/cherrypick.go
new file mode 100644
index 000000000..8983a7a52
--- /dev/null
+++ b/vendor/github.com/libgit2/git2go/cherrypick.go
@@ -0,0 +1,75 @@
+package git
+
+/*
+#include <git2.h>
+*/
+import "C"
+import (
+ "runtime"
+)
+
+type CherrypickOptions struct {
+ Version uint
+ Mainline uint
+ MergeOpts MergeOptions
+ CheckoutOpts CheckoutOpts
+}
+
+func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
+ opts := CherrypickOptions{
+ Version: uint(c.version),
+ Mainline: uint(c.mainline),
+ MergeOpts: mergeOptionsFromC(&c.merge_opts),
+ CheckoutOpts: checkoutOptionsFromC(&c.checkout_opts),
+ }
+ return opts
+}
+
+func (opts *CherrypickOptions) toC() *C.git_cherrypick_options {
+ if opts == nil {
+ return nil
+ }
+ c := C.git_cherrypick_options{}
+ c.version = C.uint(opts.Version)
+ c.mainline = C.uint(opts.Mainline)
+ c.merge_opts = *opts.MergeOpts.toC()
+ c.checkout_opts = *opts.CheckoutOpts.toC()
+ return &c
+}
+
+func freeCherrypickOpts(ptr *C.git_cherrypick_options) {
+ if ptr == nil {
+ return
+ }
+ freeCheckoutOpts(&ptr.checkout_opts)
+}
+
+func DefaultCherrypickOptions() (CherrypickOptions, error) {
+ c := C.git_cherrypick_options{}
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ecode := C.git_cherrypick_init_options(&c, C.GIT_CHERRYPICK_OPTIONS_VERSION)
+ if ecode < 0 {
+ return CherrypickOptions{}, MakeGitError(ecode)
+ }
+ defer freeCherrypickOpts(&c)
+ return cherrypickOptionsFromC(&c), nil
+}
+
+func (v *Repository) Cherrypick(commit *Commit, opts CherrypickOptions) error {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ cOpts := opts.toC()
+ defer freeCherrypickOpts(cOpts)
+
+ ecode := C.git_cherrypick(v.ptr, commit.cast_ptr, cOpts)
+ runtime.KeepAlive(v)
+ runtime.KeepAlive(commit)
+ if ecode < 0 {
+ return MakeGitError(ecode)
+ }
+ return nil
+}