summaryrefslogtreecommitdiff
path: root/remote.go
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2019-01-12 20:56:16 +0000
committerlhchavez <[email protected]>2020-02-23 08:24:06 -0800
commit37f732a833466e884fe6bf5b5612b677d485632a (patch)
treebaa6a80db2626285efca0c656b67c64cd3c1e65b /remote.go
parent45097a857c3df900111d49b9c07f2ad4645c1450 (diff)
Fix the Cred interface
This change adds Cred.Free() and finalizers to prevent memory leaks. It also makes the interface for Cred more idiomatic and return actual errors intead of ints.
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/remote.go b/remote.go
index 43ffd33..c966aab 100644
--- a/remote.go
+++ b/remote.go
@@ -51,7 +51,7 @@ const (
type TransportMessageCallback func(str string) ErrorCode
type CompletionCallback func(RemoteCompletion) ErrorCode
-type CredentialsCallback func(url string, username_from_url string, allowed_types CredType) (ErrorCode, *Cred)
+type CredentialsCallback func(url string, username_from_url string, allowed_types CredType) (*Cred, error)
type TransferProgressCallback func(stats TransferProgress) ErrorCode
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
@@ -246,11 +246,17 @@ func credentialsCallback(_cred **C.git_cred, _url *C.char, _username_from_url *C
}
url := C.GoString(_url)
username_from_url := C.GoString(_username_from_url)
- ret, cred := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
+ cred, err := callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
+ if err != nil {
+ if gitError, ok := err.(*GitError); ok {
+ return int(gitError.Code)
+ }
+ return C.GIT_EUSER
+ }
if cred != nil {
*_cred = cred.ptr
}
- return int(ret)
+ return 0
}
//export transferProgressCallback