Commit ab46b1d8ebcdc820aefe2c1391d4be73939bce95

Carlos Martín Nieto 2013-10-23T15:08:18

indexer: include the delta stats The user is unable to derive the number of deltas in the pack, as that would require them to capture the stats exactly in the moment between download and final processing, which is abstracted away in the fetch. Capture these numbers for the user and expose them in the progress struct. The clone and fetch examples now also present this information to the user.

diff --git a/examples/network/clone.c b/examples/network/clone.c
index a09a947..54c90af 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -25,13 +25,19 @@ static void print_progress(const progress_data *pd)
 		: 0.f;
 	int kbytes = pd->fetch_progress.received_bytes / 1024;
 
-	printf("net %3d%% (%4d kb, %5d/%5d)  /  idx %3d%% (%5d/%5d)  /  chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n",
+	if (pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) {
+		printf("Resolving deltas %d/%d\r",
+		       pd->fetch_progress.indexed_deltas,
+		       pd->fetch_progress.total_deltas);
+	} else {
+		printf("net %3d%% (%4d kb, %5d/%5d)  /  idx %3d%% (%5d/%5d)  /  chk %3d%% (%4" PRIuZ "/%4" PRIuZ ") %s\n",
 		   network_percent, kbytes,
 		   pd->fetch_progress.received_objects, pd->fetch_progress.total_objects,
 		   index_percent, pd->fetch_progress.indexed_objects, pd->fetch_progress.total_objects,
 		   checkout_percent,
 		   pd->completed_steps, pd->total_steps,
 		   pd->path);
+	}
 }
 
 static int fetch_progress(const git_transfer_progress *stats, void *payload)
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index 50ec003..b4f6a6a 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -72,6 +72,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 	const git_transfer_progress *stats;
 	struct dl_data data;
 	git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+	int resolve_deltas_ln = 0;
 #ifndef _WIN32
 	pthread_t worker;
 #endif
@@ -113,10 +114,14 @@ int fetch(git_repository *repo, int argc, char **argv)
 	do {
 		usleep(10000);
 
-		if (stats->total_objects > 0)
+		if (stats->received_objects == stats->total_objects) {
+			printf("Resolving deltas %d/%d\r",
+			       stats->indexed_deltas, stats->total_deltas);
+		} else if (stats->total_objects > 0) {
 			printf("Received %d/%d objects (%d) in %" PRIuZ " bytes\r",
 			       stats->received_objects, stats->total_objects,
 				   stats->indexed_objects, stats->received_bytes);
+		}
 	} while (!data.finished);
 
 	if (data.ret < 0)
diff --git a/include/git2/types.h b/include/git2/types.h
index 4ff2ba4..2d18d38 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -225,6 +225,8 @@ typedef struct git_transfer_progress {
 	unsigned int indexed_objects;
 	unsigned int received_objects;
 	unsigned int local_objects;
+	unsigned int total_deltas;
+	unsigned int indexed_deltas;
 	size_t received_bytes;
 } git_transfer_progress;
 
diff --git a/src/indexer.c b/src/indexer.c
index 93ad116..f6e9ad9 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -483,6 +483,8 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
 
 		stats->received_objects = 0;
 		stats->local_objects = 0;
+		stats->total_deltas = 0;
+		stats->indexed_deltas = 0;
 		processed = stats->indexed_objects = 0;
 		stats->total_objects = total_objects;
 		do_progress_callback(idx, stats);
@@ -758,6 +760,7 @@ static int resolve_deltas(git_indexer_stream *idx, git_transfer_progress *stats)
 
 			git__free(obj.data);
 			stats->indexed_objects++;
+			stats->indexed_deltas++;
 			progressed = 1;
 			do_progress_callback(idx, stats);
 
@@ -866,6 +869,9 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
 		return -1;
 	}
 
+	/* Freeze the number of deltas */
+	stats->total_deltas = stats->total_objects - stats->indexed_objects;
+
 	if (resolve_deltas(idx, stats) < 0)
 		return -1;