Commit 81eecc342b3580e9b05e501c8ee75c7e2e0dca1a

Ben Straub 2012-10-29T13:34:14

Fetch: don't clobber received count This memset was being reached after the entire packfile under WinHttp, so the byte count was being lost for small repos.

diff --git a/src/indexer.c b/src/indexer.c
index 4ebcdc6..ec4ef71 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -338,7 +338,8 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
 		if (git_vector_init(&idx->deltas, (unsigned int)(idx->nr_objects / 2), NULL) < 0)
 			return -1;
 
-		memset(stats, 0, sizeof(git_transfer_progress));
+		stats->received_objects = 0;
+		stats->indexed_objects = 0;
 		stats->total_objects = (unsigned int)idx->nr_objects;
 		do_progress_callback(idx, stats);
 	}
diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c
index e71e020..be1a21c 100644
--- a/tests-clar/network/fetch.c
+++ b/tests-clar/network/fetch.c
@@ -30,16 +30,15 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b, 
 
 static void progress(const git_transfer_progress *stats, void *payload)
 {
-	bool *was_called = (bool*)payload;
-	GIT_UNUSED(stats);
-	*was_called = true;
+	int *bytes_received = (int*)payload;
+	*bytes_received = stats->received_bytes;
 }
 
 static void do_fetch(const char *url, int flag, int n)
 {
 	git_remote *remote;
 	git_remote_callbacks callbacks;
-	bool progress_was_called = false;
+	int bytes_received = 0;
 
 	memset(&callbacks, 0, sizeof(git_remote_callbacks));
 	callbacks.update_tips = update_tips;
@@ -49,11 +48,11 @@ 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, progress, &progress_was_called));
+	cl_git_pass(git_remote_download(remote, progress, &bytes_received));
 	git_remote_disconnect(remote);
 	cl_git_pass(git_remote_update_tips(remote));
 	cl_assert_equal_i(counter, n);
-	cl_assert_equal_i(progress_was_called, true);
+	cl_assert(bytes_received > 0);
 
 	git_remote_free(remote);
 }