diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-11-02 00:05:32 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-11-11 15:35:51 +0100 |
commit | 359dce726d215be65aee719c7316b43e3851c031 (patch) | |
tree | 7a4a0c0af01d2d02683a3aed27eca8315f1f9ca0 /examples | |
parent | 266af6d81960144334c16e061f1d30f94f8a1b46 (diff) | |
download | libgit2-359dce726d215be65aee719c7316b43e3851c031.tar.gz |
remote: make _ls return the list directly
The callback-based method of listing remote references dates back to the
beginning of the network code's lifetime, when we didn't know any
better.
We need to keep the list around for update_tips() after disconnect() so
let's make use of this to simply give the user a pointer to the array so
they can write straightforward code instead of having to go through a
callback.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/network/ls-remote.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c index 18cd02367..1e08b293e 100644 --- a/examples/network/ls-remote.c +++ b/examples/network/ls-remote.c @@ -4,21 +4,12 @@ #include <string.h> #include "common.h" -/** Callback to show each item */ -static int show_ref__cb(git_remote_head *head, void *payload) -{ - char oid[GIT_OID_HEXSZ + 1] = {0}; - - (void)payload; - git_oid_fmt(oid, &head->oid); - printf("%s\t%s\n", oid, head->name); - return 0; -} - static int use_remote(git_repository *repo, char *name) { git_remote *remote = NULL; int error; + const git_remote_head **refs; + size_t refs_len, i; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; // Find the remote by name @@ -40,7 +31,18 @@ static int use_remote(git_repository *repo, char *name) if (error < 0) goto cleanup; - error = git_remote_ls(remote, &show_ref__cb, NULL); + /** + * Get the list of references on the remote and print out + * their name next to what they point to. + */ + if (git_remote_ls(&refs, &refs_len, remote) < 0) + goto cleanup; + + for (i = 0; i < refs_len; i++) { + char oid[GIT_OID_HEXSZ + 1] = {0}; + git_oid_fmt(oid, &refs[i]->oid); + printf("%s\t%s\n", oid, refs[i]->name); + } cleanup: git_remote_free(remote); |