aboutsummaryrefslogtreecommitdiffstats
path: root/cshared/repository_cshared.go
diff options
context:
space:
mode:
authorVadim Markovtsev <vadim@sourced.tech>2016-06-10 18:49:50 +0200
committerVadim Markovtsev <vadim@sourced.tech>2016-06-15 10:29:46 +0200
commitbea415417e87fbb403095e8cd3fb8512a1a97af8 (patch)
treee34cbd4d5dc894be5d6f9cc9570366b1cbc5f5ed /cshared/repository_cshared.go
parent08f9e7015aad2ca768638b446fb8632f11601899 (diff)
downloadgo-git-bea415417e87fbb403095e8cd3fb8512a1a97af8.tar.gz
Add cshared files to allow building wrappers in other languages
Diffstat (limited to 'cshared/repository_cshared.go')
-rw-r--r--cshared/repository_cshared.go247
1 files changed, 247 insertions, 0 deletions
diff --git a/cshared/repository_cshared.go b/cshared/repository_cshared.go
new file mode 100644
index 0000000..6ca600f
--- /dev/null
+++ b/cshared/repository_cshared.go
@@ -0,0 +1,247 @@
+// +build ignore
+package main
+
+import (
+ "C"
+
+ "gopkg.in/src-d/go-git.v3"
+ "gopkg.in/src-d/go-git.v3/core"
+ "gopkg.in/src-d/go-git.v3/clients/common"
+)
+
+//export c_Repository
+func c_Repository() uint64 {
+ repo := &git.Repository{}
+ repo_handle := RegisterObject(repo)
+ return uint64(repo_handle)
+}
+
+//export c_NewRepository
+func c_NewRepository(url string, auth uint64) (uint64, int, *C.char) {
+ var repo *git.Repository
+ var err error
+ url = CopyString(url)
+ if auth != IH {
+ real_auth, ok := GetObject(Handle(auth))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo, err = git.NewRepository(url, real_auth.(common.AuthMethod))
+ } else {
+ repo, err = git.NewRepository(url, nil)
+ }
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ repo_handle := RegisterObject(repo)
+ return uint64(repo_handle), ErrorCodeSuccess, nil
+}
+
+//export c_NewPlainRepository
+func c_NewPlainRepository() uint64 {
+ return uint64(RegisterObject(git.NewPlainRepository()))
+}
+
+//export c_Repository_get_Remotes
+func c_Repository_get_Remotes(r uint64) uint64 {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH
+ }
+ repo := obj.(*git.Repository)
+ return uint64(RegisterObject(&repo.Remotes))
+}
+
+//export c_Repository_set_Remotes
+func c_Repository_set_Remotes(r uint64, val uint64) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return
+ }
+ repo := obj.(*git.Repository)
+ obj, ok = GetObject(Handle(val))
+ if !ok {
+ return
+ }
+ repo.Remotes = *obj.(*map[string]*git.Remote)
+}
+
+//export c_Repository_get_Storage
+func c_Repository_get_Storage(r uint64) uint64 {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH
+ }
+ repo := obj.(*git.Repository)
+ return uint64(RegisterObject(&repo.Storage))
+}
+
+//export c_Repository_set_Storage
+func c_Repository_set_Storage(r uint64, val uint64) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return
+ }
+ repo := obj.(*git.Repository)
+ obj, ok = GetObject(Handle(val))
+ if !ok {
+ return
+ }
+ repo.Storage = *obj.(*core.ObjectStorage)
+}
+
+//export c_Repository_get_URL
+func c_Repository_get_URL(r uint64) *C.char {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return nil
+ }
+ return C.CString(obj.(*git.Repository).URL)
+}
+
+//export c_Repository_set_URL
+func c_Repository_set_URL(r uint64, val string) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return
+ }
+ repo := obj.(*git.Repository)
+ repo.URL = CopyString(val)
+}
+
+//export c_Repository_Pull
+func c_Repository_Pull(r uint64, remoteName, branch string) (int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ err := repo.Pull(remoteName, CopyString(branch))
+ if err == nil {
+ return ErrorCodeSuccess, nil
+ }
+ return ErrorCodeInternal, C.CString(err.Error())
+}
+
+//export c_Repository_PullDefault
+func c_Repository_PullDefault(r uint64) (int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ err := repo.PullDefault()
+ if err == nil {
+ return ErrorCodeSuccess, nil
+ }
+ return ErrorCodeInternal, C.CString(err.Error())
+}
+
+//export c_Repository_Commit
+func c_Repository_Commit(r uint64, h []byte) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ var hash core.Hash
+ copy(hash[:], h)
+ commit, err := repo.Commit(hash)
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ commit_handle := RegisterObject(commit)
+ return uint64(commit_handle), ErrorCodeSuccess, nil
+}
+
+//export c_Repository_Commits
+func c_Repository_Commits(r uint64) uint64 {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH
+ }
+ repo := obj.(*git.Repository)
+ iter := repo.Commits()
+ iter_handle := RegisterObject(iter)
+ return uint64(iter_handle)
+}
+
+//export c_Repository_Tree
+func c_Repository_Tree(r uint64, h []byte) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ var hash core.Hash
+ copy(hash[:], h)
+ tree, err := repo.Tree(hash)
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ tree_handle := RegisterObject(tree)
+ return uint64(tree_handle), ErrorCodeSuccess, nil
+}
+
+//export c_Repository_Blob
+func c_Repository_Blob(r uint64, h []byte) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ var hash core.Hash
+ copy(hash[:], h)
+ blob, err := repo.Blob(hash)
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ blob_handle := RegisterObject(blob)
+ return uint64(blob_handle), ErrorCodeSuccess, nil
+}
+
+//export c_Repository_Tag
+func c_Repository_Tag(r uint64, h []byte) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ var hash core.Hash
+ copy(hash[:], h)
+ tag, err := repo.Tag(hash)
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ tag_handle := RegisterObject(tag)
+ return uint64(tag_handle), ErrorCodeSuccess, nil
+}
+
+//export c_Repository_Tags
+func c_Repository_Tags(r uint64) uint64 {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH
+ }
+ repo := obj.(*git.Repository)
+ iter := repo.Tags()
+ iter_handle := RegisterObject(iter)
+ return uint64(iter_handle)
+}
+
+//export c_Repository_Object
+func c_Repository_Object(r uint64, h []byte) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(r))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ repo := obj.(*git.Repository)
+ var hash core.Hash
+ copy(hash[:], h)
+ robj, err := repo.Object(hash)
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ robj_handle := RegisterObject(robj)
+ return uint64(robj_handle), ErrorCodeSuccess, nil
+}