Commit ae789622e438e213d8a2059f7aeeeae931442c18

Carlos Martín Nieto 2012-07-25T10:52:20

examples: fix warnings in network/

diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 157f914..52e0412 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -40,9 +40,8 @@ exit:
 	pthread_exit(&data->ret);
 }
 
-int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
+static 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];
 
 	git_oid_fmt(b_str, b);
@@ -68,6 +67,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 	struct dl_data data;
 	git_remote_callbacks callbacks;
 
+	argc = argc;
 	// Figure out whether it's a named remote or a URL
 	printf("Fetching %s\n", argv[1]);
 	if (git_remote_load(&remote, repo, argv[1]) < 0) {
@@ -96,13 +96,14 @@ int fetch(git_repository *repo, int argc, char **argv)
 	// the download rate.
 	do {
 		usleep(10000);
-		printf("\rReceived %d/%d objects in %d bytes", stats.processed, stats.total, bytes);
+		printf("\rReceived %d/%d objects in %zu bytes", stats.processed, stats.total, bytes);
 	} while (!data.finished);
 
 	if (data.ret < 0)
 		goto on_error;
 
-	printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
+	pthread_join(worker, NULL);
+	printf("\rReceived %d/%d objects in %zu bytes\n", stats.processed, stats.total, bytes);
 
 	// Disconnect the underlying connection to prevent from idling.
 	git_remote_disconnect(remote);
diff --git a/examples/network/git2.c b/examples/network/git2.c
index 7c02305..1bfb13c 100644
--- a/examples/network/git2.c
+++ b/examples/network/git2.c
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "common.h"
 
@@ -16,7 +17,7 @@ struct {
 	{ NULL, NULL}
 };
 
-int run_command(git_cb fn, int argc, char **argv)
+static int run_command(git_cb fn, int argc, char **argv)
 {
 	int error;
 	git_repository *repo;
@@ -45,7 +46,7 @@ int run_command(git_cb fn, int argc, char **argv)
 
 int main(int argc, char **argv)
 {
-	int i, error;
+	int i;
 
 	if (argc < 2) {
 		fprintf(stderr, "usage: %s <cmd> [repo]\n", argv[0]);
diff --git a/examples/network/index-pack.c b/examples/network/index-pack.c
index ef5a359..85aac4a 100644
--- a/examples/network/index-pack.c
+++ b/examples/network/index-pack.c
@@ -2,13 +2,20 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include "common.h"
 
 // This could be run in the main loop whilst the application waits for
 // the indexing to finish in a worker thread
-int index_cb(const git_indexer_stats *stats, void *data)
+static int index_cb(const git_indexer_stats *stats, void *data)
 {
+	data = data;
 	printf("\rProcessing %d of %d", stats->processed, stats->total);
+
+	return 0;
 }
 
 int index_pack(git_repository *repo, int argc, char **argv)
@@ -20,6 +27,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
 	ssize_t read_bytes;
 	char buf[512];
 
+	repo = repo;
 	if (argc < 2) {
 		fprintf(stderr, "I need a packfile\n");
 		return EXIT_FAILURE;
@@ -43,7 +51,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
 		if ((error = git_indexer_stream_add(idx, buf, read_bytes, &stats)) < 0)
 			goto cleanup;
 
-		printf("\rIndexing %d of %d", stats.processed, stats.total);
+		index_cb(&stats, NULL);
 	} while (read_bytes > 0);
 
 	if (read_bytes < 0) {
@@ -65,38 +73,3 @@ int index_pack(git_repository *repo, int argc, char **argv)
 	git_indexer_stream_free(idx);
 	return error;
 }
-
-int index_pack_old(git_repository *repo, int argc, char **argv)
-{
-	git_indexer *indexer;
-	git_indexer_stats stats;
-	int error;
-	char hash[GIT_OID_HEXSZ + 1] = {0};
-
-	if (argc < 2) {
-		fprintf(stderr, "I need a packfile\n");
-		return EXIT_FAILURE;
-	}
-
-	// Create a new indexer
-	error = git_indexer_new(&indexer, argv[1]);
-	if (error < 0)
-		return error;
-
-	// Index the packfile. This function can take a very long time and
-	// should be run in a worker thread.
-	error = git_indexer_run(indexer, &stats);
-	if (error < 0)
-		return error;
-
-	// Write the information out to an index file
-	error = git_indexer_write(indexer);
-
-	// Get the packfile's hash (which should become it's filename)
-	git_oid_fmt(hash, git_indexer_hash(indexer));
-	puts(hash);
-
-	git_indexer_free(indexer);
-
-	return 0;
-}
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index 39cc647..822d6f6 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -7,12 +7,14 @@
 static int show_ref__cb(git_remote_head *head, void *payload)
 {
 	char oid[GIT_OID_HEXSZ + 1] = {0};
+
+	payload = payload;
 	git_oid_fmt(oid, &head->oid);
 	printf("%s\t%s\n", oid, head->name);
 	return 0;
 }
 
-int use_unnamed(git_repository *repo, const char *url)
+static int use_unnamed(git_repository *repo, const char *url)
 {
 	git_remote *remote = NULL;
 	int error;
@@ -37,7 +39,7 @@ cleanup:
 	return error;
 }
 
-int use_remote(git_repository *repo, char *name)
+static int use_remote(git_repository *repo, char *name)
 {
 	git_remote *remote = NULL;
 	int error;
@@ -63,8 +65,9 @@ cleanup:
 
 int ls_remote(git_repository *repo, int argc, char **argv)
 {
-	int error, i;
+	int error;
 
+	argc = argc;
 	/* If there's a ':' in the name, assume it's an URL */
 	if (strchr(argv[1], ':') != NULL) {
 		error = use_unnamed(repo, argv[1]);