diff options
| author | lhchavez <[email protected]> | 2019-01-12 20:56:16 +0000 |
|---|---|---|
| committer | lhchavez <[email protected]> | 2020-02-23 08:24:06 -0800 |
| commit | 37f732a833466e884fe6bf5b5612b677d485632a (patch) | |
| tree | baa6a80db2626285efca0c656b67c64cd3c1e65b /remote.go | |
| parent | 45097a857c3df900111d49b9c07f2ad4645c1450 (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.go | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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 |
