summaryrefslogtreecommitdiff
path: root/remote.go
diff options
context:
space:
mode:
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go182
1 files changed, 137 insertions, 45 deletions
diff --git a/remote.go b/remote.go
index 5300c42..38c1d47 100644
--- a/remote.go
+++ b/remote.go
@@ -19,10 +19,11 @@ type TransferProgress struct {
}
type RemoteCompletion uint
+
const (
RemoteCompletionDownload RemoteCompletion = C.GIT_REMOTE_COMPLETION_DOWNLOAD
- RemoteCompletionIndexing = C.GIT_REMOTE_COMPLETION_INDEXING
- RemoteCompletionError = C.GIT_REMOTE_COMPLETION_ERROR
+ RemoteCompletionIndexing = C.GIT_REMOTE_COMPLETION_INDEXING
+ RemoteCompletionError = C.GIT_REMOTE_COMPLETION_ERROR
)
type ProgressCallback func(str string) int
@@ -40,21 +41,21 @@ type RemoteCallbacks struct {
}
type Remote interface {
- Save() int
+ Save() error
Owner() Repository
Name() string
Url() string
PushUrl() string
-
- SetUrl(url string) int
- SetPushUrl(url string) int
- AddFetch(refspec string) int
- GetFetchRefspecs() (err int, refspecs []string)
- SetFetchRefspecs(refspecs []string) int
- AddPush(refspec string) int
- GetPushRefspecs() (err int, refspecs []string)
- SetPushRefspecs(refspecs []string) int
+ SetUrl(url string) error
+ SetPushUrl(url string) error
+
+ AddFetch(refspec string) error
+ GetFetchRefspecs() ([]string, error)
+ SetFetchRefspecs(refspecs []string) error
+ AddPush(refspec string) error
+ GetPushRefspecs() ([]string, error)
+ SetPushRefspecs(refspecs []string) error
ClearRefspecs()
RefspecCount() uint
}
@@ -164,20 +165,26 @@ func freeRemote(o *gitRemote) {
C.git_remote_free(o.ptr)
}
-func CreateRemote(repo *Repository, name string, url string) (int, Remote) {
+func CreateRemote(repo *Repository, name string, url string) (Remote, error) {
remote := &gitRemote{}
runtime.SetFinalizer(remote, freeRemote)
-
+
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
ret := C.git_remote_create(&remote.ptr, repo.ptr, cname, curl)
- return int(ret), remote
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+ return remote, nil
}
-func CreateRemoteWithFetchspec(repo *Repository, name string, url string, fetch string) (int, Remote) {
+func CreateRemoteWithFetchspec(repo *Repository, name string, url string, fetch string) (Remote, error) {
remote := &gitRemote{}
runtime.SetFinalizer(remote, freeRemote)
@@ -188,11 +195,17 @@ func CreateRemoteWithFetchspec(repo *Repository, name string, url string, fetch
cfetch := C.CString(fetch)
defer C.free(unsafe.Pointer(cfetch))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
ret := C.git_remote_create_with_fetchspec(&remote.ptr, repo.ptr, cname, curl, cfetch)
- return int(ret), remote
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+ return remote, nil
}
-func CreateRemoteInMemory(repo *Repository, fetch string, url string) (int, Remote) {
+func CreateRemoteInMemory(repo *Repository, fetch string, url string) (Remote, error) {
remote := &gitRemote{}
runtime.SetFinalizer(remote, freeRemote)
@@ -201,28 +214,48 @@ func CreateRemoteInMemory(repo *Repository, fetch string, url string) (int, Remo
cfetch := C.CString(fetch)
defer C.free(unsafe.Pointer(cfetch))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
ret := C.git_remote_create_inmemory(&remote.ptr, repo.ptr, cfetch, curl)
- return int(ret), remote
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+ return remote, nil
}
-func LoadRemote(repo *Repository, name string) (int, Remote) {
+func LoadRemote(repo *Repository, name string) (Remote, error) {
remote := &gitRemote{}
runtime.SetFinalizer(remote, freeRemote)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
ret := C.git_remote_load(&remote.ptr, repo.ptr, cname)
- return int(ret), remote
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+ return remote, nil
}
-func (o *gitRemote) Save() int {
- return int(C.git_remote_save(o.ptr))
+func (o *gitRemote) Save() error {
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_save(o.ptr)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
func (o *gitRemote) Owner() Repository {
return Repository{C.git_remote_owner(o.ptr)}
-}
+}
func (o *gitRemote) Name() string {
return C.GoString(C.git_remote_name(o.ptr))
@@ -236,37 +269,68 @@ func (o *gitRemote) PushUrl() string {
return C.GoString(C.git_remote_pushurl(o.ptr))
}
-func (o *gitRemote) SetUrl(url string) int {
+func (o *gitRemote) SetUrl(url string) error {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
- return int(C.git_remote_set_url(o.ptr, curl))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_set_url(o.ptr, curl)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
-func (o *gitRemote) SetPushUrl(url string) int {
+func (o *gitRemote) SetPushUrl(url string) error {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
- return int(C.git_remote_set_pushurl(o.ptr, curl))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_set_pushurl(o.ptr, curl)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
-func (o *gitRemote) AddFetch(refspec string) int {
+func (o *gitRemote) AddFetch(refspec string) error {
crefspec := C.CString(refspec)
defer C.free(unsafe.Pointer(crefspec))
- return int(C.git_remote_add_fetch(o.ptr, crefspec))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_add_fetch(o.ptr, crefspec)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
-func (o *gitRemote) GetFetchRefspecs() (err int, refspecs []string) {
+func (o *gitRemote) GetFetchRefspecs() ([]string, error) {
crefspecs := C.git_strarray{}
- err = int(C.git_remote_get_fetch_refspecs(&crefspecs, o.ptr))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_get_fetch_refspecs(&crefspecs, o.ptr)
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
defer C.git_strarray_free(&crefspecs)
- refspecs = make([]string, crefspecs.count)
+ refspecs := make([]string, crefspecs.count)
for i := 0; i < int(crefspecs.count); i++ {
refspecs[i] = C.GoString(C._go_git_get_strarray_n(&crefspecs, C.size_t(i)))
}
- return
+ return refspecs, nil
}
-func (o *gitRemote) SetFetchRefspecs(refspecs []string) int {
+func (o *gitRemote) SetFetchRefspecs(refspecs []string) error {
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = (**C.char)(C.malloc(C.size_t(unsafe.Sizeof(unsafe.Pointer(nil)) * uintptr(crefspecs.count))))
@@ -275,28 +339,50 @@ func (o *gitRemote) SetFetchRefspecs(refspecs []string) int {
}
defer C.git_strarray_free(&crefspecs)
- return int(C.git_remote_set_fetch_refspecs(o.ptr, &crefspecs))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_set_fetch_refspecs(o.ptr, &crefspecs)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
-func (o *gitRemote) AddPush(refspec string) int {
+func (o *gitRemote) AddPush(refspec string) error {
crefspec := C.CString(refspec)
defer C.free(unsafe.Pointer(crefspec))
- return int(C.git_remote_add_push(o.ptr, crefspec))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_add_push(o.ptr, crefspec)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
-func (o *gitRemote) GetPushRefspecs() (err int, refspecs []string) {
+func (o *gitRemote) GetPushRefspecs() ([]string, error) {
crefspecs := C.git_strarray{}
- err = int(C.git_remote_get_push_refspecs(&crefspecs, o.ptr))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_get_push_refspecs(&crefspecs, o.ptr)
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
defer C.git_strarray_free(&crefspecs)
- refspecs = make([]string, crefspecs.count)
+ refspecs := make([]string, crefspecs.count)
for i := 0; i < int(crefspecs.count); i++ {
refspecs[i] = C.GoString(C._go_git_get_strarray_n(&crefspecs, C.size_t(i)))
}
- return
+ return refspecs, nil
}
-func (o *gitRemote) SetPushRefspecs(refspecs []string) int {
+func (o *gitRemote) SetPushRefspecs(refspecs []string) error {
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = (**C.char)(C.malloc(C.size_t(unsafe.Sizeof(unsafe.Pointer(nil)) * uintptr(crefspecs.count))))
@@ -305,7 +391,14 @@ func (o *gitRemote) SetPushRefspecs(refspecs []string) int {
}
defer C.git_strarray_free(&crefspecs)
- return int(C.git_remote_set_push_refspecs(o.ptr, &crefspecs))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_remote_set_push_refspecs(o.ptr, &crefspecs)
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
}
func (o *gitRemote) ClearRefspecs() {
@@ -315,4 +408,3 @@ func (o *gitRemote) ClearRefspecs() {
func (o *gitRemote) RefspecCount() uint {
return uint(C.git_remote_refspec_count(o.ptr))
}
-