Commit 1e3b8ed5cfe784f73a123c33c90f573742d8839e

Ben Straub 2012-10-24T14:07:07

Remove 'bytes' param from git_remote_download

diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 8bfe10c..496498e 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -8,7 +8,6 @@
 
 struct dl_data {
 	git_remote *remote;
-	git_off_t *bytes;
 	int ret;
 	int finished;
 };
@@ -34,7 +33,7 @@ static void *download(void *ptr)
 	// Download the packfile and index it. This function updates the
 	// amount of received data and the indexer stats which lets you
 	// inform the user about progress.
-	if (git_remote_download(data->remote, data->bytes, NULL, NULL) < 0) {
+	if (git_remote_download(data->remote, NULL, NULL) < 0) {
 		data->ret = -1;
 		goto exit;
 	}
@@ -68,7 +67,6 @@ static int update_cb(const char *refname, const git_oid *a, const git_oid *b, vo
 int fetch(git_repository *repo, int argc, char **argv)
 {
 	git_remote *remote = NULL;
-	git_off_t bytes = 0;
 	const git_transfer_progress *stats;
 	pthread_t worker;
 	struct dl_data data;
@@ -90,7 +88,6 @@ int fetch(git_repository *repo, int argc, char **argv)
 
 	// Set up the information for the background worker thread
 	data.remote = remote;
-	data.bytes = &bytes;
 	data.ret = 0;
 	data.finished = 0;
 
@@ -108,7 +105,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 		if (stats->total_objects > 0)
 			printf("Received %d/%d objects (%d) in %d bytes\r",
 			       stats->received_objects, stats->total_objects,
-					 stats->indexed_objects, bytes);
+					 stats->indexed_objects, stats->received_bytes);
 	} while (!data.finished);
 
 	if (data.ret < 0)
@@ -116,7 +113,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 
 	pthread_join(worker, NULL);
 	printf("\rReceived %d/%d objects in %zu bytes\n",
-			stats->indexed_objects, stats->total_objects, bytes);
+			stats->indexed_objects, stats->total_objects, stats->received_bytes);
 
 	// Disconnect the underlying connection to prevent from idling.
 	git_remote_disconnect(remote);
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 897dfde..1ec1a08 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -183,8 +183,6 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void 
  * filename will be NULL and the function will return success.
  *
  * @param remote the remote to download from
- * @param bytes buffer that receives the number of bytes transferred (updated
- * while transfer is in progress)
  * @param progress_cb function to call with progress information.  Be aware that
  * this is called inline with network and indexing operations, so performance
  * may be affected.
@@ -193,7 +191,6 @@ GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void 
  */
 GIT_EXTERN(int) git_remote_download(
 		git_remote *remote,
-		git_off_t *bytes,
 		git_transfer_progress_callback progress_cb,
 		void *progress_payload);
 
diff --git a/src/clone.c b/src/clone.c
index fc2bfa1..ab8b9bc 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -256,13 +256,12 @@ static int setup_remotes_and_fetch(
 {
 	int retcode = GIT_ERROR;
 	git_remote *origin = NULL;
-	git_off_t bytes = 0;
 
 	/* Create the "origin" remote */
 	if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) {
 		/* Connect and download everything */
 		if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
-			if (!git_remote_download(origin, &bytes, progress_cb, progress_payload)) {
+			if (!git_remote_download(origin, progress_cb, progress_payload)) {
 				/* Create "origin/foo" branches for all remote branches */
 				if (!git_remote_update_tips(origin)) {
 					/* Point HEAD to the same ref as the remote's head */
diff --git a/src/fetch.c b/src/fetch.c
index ee85f08..0aabe74 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -306,7 +306,6 @@ on_error:
 
 int git_fetch_download_pack(
 		git_remote *remote,
-		git_off_t *bytes,
 		git_transfer_progress_callback progress_cb,
 		void *progress_payload)
 {
@@ -316,14 +315,14 @@ int git_fetch_download_pack(
 		return 0;
 
 	if (t->own_logic)
-		return t->download_pack(t, remote->repo, bytes, &remote->stats);
+		return t->download_pack(t, remote->repo, &remote->stats);
 
-	return git_fetch__download_pack(t, remote->repo, bytes, &remote->stats,
+	return git_fetch__download_pack(t, remote->repo, &remote->stats,
 			progress_cb, progress_payload);
 
 }
 
-static int no_sideband(git_transport *t, git_indexer_stream *idx, gitno_buffer *buf, git_off_t *bytes, git_transfer_progress *stats)
+static int no_sideband(git_transport *t, git_indexer_stream *idx, gitno_buffer *buf, git_transfer_progress *stats)
 {
 	int recvd;
 
@@ -340,8 +339,6 @@ static int no_sideband(git_transport *t, git_indexer_stream *idx, gitno_buffer *
 
 		if ((recvd = gitno_recv(buf)) < 0)
 			return -1;
-
-		*bytes += recvd;
 	} while(recvd > 0);
 
 	if (git_indexer_stream_finalize(idx, stats))
@@ -376,7 +373,6 @@ static void network_packetsize(int received, void *payload)
 int git_fetch__download_pack(
 	git_transport *t,
 	git_repository *repo,
-	git_off_t *bytes,
 	git_transfer_progress *stats,
 	git_transfer_progress_callback progress_cb,
 	void *progress_payload)
@@ -403,7 +399,6 @@ int git_fetch__download_pack(
 
 	git_buf_free(&path);
 	memset(stats, 0, sizeof(git_transfer_progress));
-	*bytes = 0;
 
 	/*
 	 * If the remote doesn't support the side-band, we can feed
@@ -411,7 +406,7 @@ int git_fetch__download_pack(
 	 * check which one belongs there.
 	 */
 	if (!t->caps.side_band && !t->caps.side_band_64k) {
-		if (no_sideband(t, idx, buf, bytes, stats) < 0)
+		if (no_sideband(t, idx, buf, stats) < 0)
 			goto on_error;
 
 		git_indexer_stream_free(idx);
@@ -438,7 +433,6 @@ int git_fetch__download_pack(
 			git__free(pkt);
 		} else if (pkt->type == GIT_PKT_DATA) {
 			git_pkt_data *p = (git_pkt_data *) pkt;
-			*bytes += p->len;
 			if (git_indexer_stream_add(idx, p->data, p->len, stats) < 0)
 				goto on_error;
 
diff --git a/src/fetch.h b/src/fetch.h
index 23d0cf6..5b8c206 100644
--- a/src/fetch.h
+++ b/src/fetch.h
@@ -13,14 +13,12 @@ int git_fetch_negotiate(git_remote *remote);
 
 int git_fetch_download_pack(
 		git_remote *remote,
-		git_off_t *bytes,
 		git_transfer_progress_callback progress_cb,
 		void *progress_payload);
 
 int git_fetch__download_pack(
 		git_transport *t,
 		git_repository *repo,
-		git_off_t *bytes,
 		git_transfer_progress *stats,
 		git_transfer_progress_callback progress_cb,
 		void *progress_payload);
diff --git a/src/remote.c b/src/remote.c
index 3e9a757..87c1ad8 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -435,18 +435,17 @@ int git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload)
 
 int git_remote_download(
 		git_remote *remote,
-		git_off_t *bytes,
 		git_transfer_progress_callback progress_cb,
 		void *progress_payload)
 {
 	int error;
 
-	assert(remote && bytes);
+	assert(remote);
 
 	if ((error = git_fetch_negotiate(remote)) < 0)
 		return error;
 
-	return git_fetch_download_pack(remote, bytes, progress_cb, progress_payload);
+	return git_fetch_download_pack(remote, progress_cb, progress_payload);
 }
 
 int git_remote_update_tips(git_remote *remote)
diff --git a/src/transport.h b/src/transport.h
index 79afae0..1a3eee5 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -113,7 +113,7 @@ struct git_transport {
 	/**
 	 * Download the packfile
 	 */
-	int (*download_pack)(struct git_transport *transport, git_repository *repo, git_off_t *bytes, git_transfer_progress *stats);
+	int (*download_pack)(struct git_transport *transport, git_repository *repo, git_transfer_progress *stats);
 	/**
 	 * Close the connection
 	 */
diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c
index c3fb15e..74e0628 100644
--- a/tests-clar/network/fetch.c
+++ b/tests-clar/network/fetch.c
@@ -38,7 +38,6 @@ static void progress(const git_transfer_progress *stats, void *payload)
 static void do_fetch(const char *url, int flag, int n)
 {
 	git_remote *remote;
-	git_off_t bytes;
 	git_remote_callbacks callbacks;
 	bool progress_was_called = false;
 
@@ -50,7 +49,7 @@ static void do_fetch(const char *url, int flag, int n)
 	git_remote_set_callbacks(remote, &callbacks);
 	git_remote_set_autotag(remote, flag);
 	cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
-	cl_git_pass(git_remote_download(remote, &bytes, progress, &progress_was_called));
+	cl_git_pass(git_remote_download(remote, progress, &progress_was_called));
 	git_remote_disconnect(remote);
 	cl_git_pass(git_remote_update_tips(remote));
 	cl_assert_equal_i(counter, n);