Last active
August 29, 2015 14:07
-
-
Save calavera/6953b7d7b8c6c1ad9a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/remote.go w/remote.go | |
index 74ebe27..d7e10c7 100644 | |
--- i/remote.go | |
+++ w/remote.go | |
@@ -5,6 +5,7 @@ package git | |
#include <git2/errors.h> | |
extern void _go_git_setup_callbacks(git_remote_callbacks *callbacks); | |
+extern int _go_git_remote_ls(git_remote *remote, const git_remote_head **refs); | |
*/ | |
import "C" | |
@@ -56,6 +57,18 @@ type Remote struct { | |
ptr *C.git_remote | |
} | |
+type RemoteHead struct { | |
+ Id *Oid | |
+ Name string | |
+} | |
+ | |
+func newRemoteHeadFromC(ptr *C.git_remote_head) *RemoteHead { | |
+ return &RemoteHead{ | |
+ Id: newOidFromC(ptr.oid), | |
+ Name: C.GoString(ptr.name), | |
+ } | |
+} | |
+ | |
func populateRemoteCallbacks(ptr *C.git_remote_callbacks, callbacks *RemoteCallbacks) { | |
C.git_remote_init_callbacks(ptr, C.GIT_REMOTE_CALLBACKS_VERSION) | |
if callbacks == nil { | |
@@ -454,3 +467,15 @@ func (o *Remote) Fetch(sig *Signature, msg string) error { | |
} | |
return nil | |
} | |
+ | |
+func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) { | |
+ heads := make([]*C.git_remote_head, 0) | |
+ | |
+ ptr := unsafe.Pointer(&heads) | |
+ ret := C._go_git_remote_ls(o.ptr, (**C.git_remote_head)(ptr)) | |
+ if ret < 0 { | |
+ return nil, MakeGitError(ret) | |
+ } | |
+ | |
+ return nil, nil | |
+} | |
diff --git i/wrapper.c w/wrapper.c | |
index 2fd8fb7..5a4101c 100644 | |
--- i/wrapper.c | |
+++ w/wrapper.c | |
@@ -105,4 +105,17 @@ int _go_git_blob_create_fromchunks(git_oid *id, | |
return git_blob_create_fromchunks(id, repo, hintpath, _go_blob_chunk_cb, payload); | |
} | |
+int _go_git_remote_ls(git_remote *remote, const git_remote_head **refs) | |
+{ | |
+ int error; | |
+ size_t refs_len; | |
+ | |
+ if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH)) != 0) | |
+ return error; | |
+ | |
+ error = git_remote_ls(&refs, &refs_len, remote) | |
+ | |
+ return error; | |
+} | |
+ | |
/* EOF */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first two arguments to
git_remote_ls()
are outputs. You should have aconst git_remote_head **
in your stack and pass in the argument. In your C function, you are throwing that information away, as the variable only exists inside_go_git_remote_ls
. I had hoped you wouldn't need to use C for this, but I'm not sure how well Go handles pointers to pointers.I haven't tried this yet, but in Go you should be able to have
var refs **C.git_remote_head
andvar len C.size_t
and callC.git_remote_ls(&refs, &len, o.ptr)
. What you then have inrefs
is a an array ofgit_remote_head
pointers.From then on, I don't know if you can ask Go to perform pointer arithmteic, but it might be a better idea to use https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices so you can use a
[]*C.git_remote_head
which would let you use it as a normal array.