summaryrefslogtreecommitdiff
path: root/examples/network/fetch.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2012-07-21 17:52:51 +0200
committerCarlos Martín Nieto <cmn@elego.de>2012-07-21 18:44:01 +0200
commitb3aaa7a7c887006d38b7262b73575d40f51beca5 (patch)
treef6ab0f132ebf96d598074e11a61922e73e2f4f87 /examples/network/fetch.c
parent5d9cfa07ac62ad15ebb669b01e723a990450383e (diff)
downloadlibgit2-b3aaa7a7c887006d38b7262b73575d40f51beca5.tar.gz
Add a struct for network callbacks
Currently only update_tips is used, but it prepares the way for progress output during download.
Diffstat (limited to 'examples/network/fetch.c')
-rw-r--r--examples/network/fetch.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index d2752124d..73bfbddd0 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+#include <unistd.h>
struct dl_data {
git_remote *remote;
@@ -39,7 +40,7 @@ exit:
pthread_exit(&data->ret);
}
-int update_cb(const char *refname, const git_oid *a, const git_oid *b)
+int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
{
const char *action;
char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1];
@@ -65,6 +66,7 @@ int fetch(git_repository *repo, int argc, char **argv)
git_indexer_stats stats;
pthread_t worker;
struct dl_data data;
+ git_remote_callbacks callbacks;
// Figure out whether it's a named remote or a URL
printf("Fetching %s\n", argv[1]);
@@ -73,6 +75,11 @@ int fetch(git_repository *repo, int argc, char **argv)
return -1;
}
+ // Set up the callbacks (only update_tips for now)
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.update_tips = &update_cb;
+ git_remote_set_callbacks(remote, &callbacks);
+
// Set up the information for the background worker thread
data.remote = remote;
data.bytes = &bytes;
@@ -101,7 +108,7 @@ int fetch(git_repository *repo, int argc, char **argv)
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
// changed but all the neede objects are available locally.
- if (git_remote_update_tips(remote, update_cb) < 0)
+ if (git_remote_update_tips(remote) < 0)
return -1;
git_remote_free(remote);