summaryrefslogtreecommitdiff
path: root/examples/network
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-11-01 09:38:34 -0700
committerVicent Martí <vicent@github.com>2013-11-01 09:38:34 -0700
commit567649f2ada60e5c3009cc985af238b452b14a81 (patch)
tree12a19dd97c05818557228ed2b3fcc36e183959b2 /examples/network
parent948f00b4e79bb60c68e03342500013246e642ae6 (diff)
parent4f62d55968d4a22a6ea03194aa34ab1b6ca8fdea (diff)
downloadlibgit2-567649f2ada60e5c3009cc985af238b452b14a81.tar.gz
Merge pull request #1916 from libgit2/simplify-examples
Fix examples to make the important stuff more obvious
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/fetch.c11
-rw-r--r--examples/network/ls-remote.c9
2 files changed, 17 insertions, 3 deletions
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 4167ef3ca..ad01001d7 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -47,6 +47,11 @@ exit:
return &data->ret;
}
+/**
+ * This function gets called for each remote-tracking branch that gets
+ * updated. The message we output depends on whether it's a new one or
+ * an update.
+ */
static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
{
char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1];
@@ -66,6 +71,7 @@ static int update_cb(const char *refname, const git_oid *a, const git_oid *b, vo
return 0;
}
+/** Entry point for this command */
int fetch(git_repository *repo, int argc, char **argv)
{
git_remote *remote = NULL;
@@ -130,6 +136,11 @@ int fetch(git_repository *repo, int argc, char **argv)
pthread_join(worker, NULL);
#endif
+ /**
+ * If there are local objects (we got a thin pack), then tell
+ * the user how many objects we saved from having to cross the
+ * network.
+ */
if (stats->local_objects > 0) {
printf("\rReceived %d/%d objects in %zu bytes (used %d local objects)\n",
stats->indexed_objects, stats->total_objects, stats->received_bytes, stats->local_objects);
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index b65759ed3..18cd02367 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -4,6 +4,7 @@
#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};
@@ -28,6 +29,10 @@ static int use_remote(git_repository *repo, char *name)
goto cleanup;
}
+ /**
+ * Connect to the remote and call the printing function for
+ * each of the remote references.
+ */
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);
@@ -42,9 +47,7 @@ cleanup:
return error;
}
-// This gets called to do the work. The remote can be given either as
-// the name of a configured remote or an URL.
-
+/** Entry point for this command */
int ls_remote(git_repository *repo, int argc, char **argv)
{
int error;