Commit 6568f37436bb42ab52d78afd3b81e5d177ed3006

Patrick Steinhardt 2017-10-11T13:20:19

indexer: remove useless local variable The `processed` variable local to `git_indexer_append` counts how many objects have already been processed. But actually, whenever it gets assigned to, we are also assigning the same value to the `stats->indexed_objects` struct member. So in fact, it is being quite useless due to always having the same value as the `indexer_objects` member and makes it a bit harder to understand the code. We can just remove the variable to fix that.

diff --git a/src/indexer.c b/src/indexer.c
index 744a03c..91b9b52 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -528,14 +528,11 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
 int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_transfer_progress *stats)
 {
 	int error = -1;
-	size_t processed;
 	struct git_pack_header *hdr = &idx->hdr;
 	git_mwindow_file *mwf = &idx->pack->mwf;
 
 	assert(idx && data && stats);
 
-	processed = stats->indexed_objects;
-
 	if ((error = append_to_pack(idx, data, size)) < 0)
 		return error;
 
@@ -578,7 +575,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
 		stats->local_objects = 0;
 		stats->total_deltas = 0;
 		stats->indexed_deltas = 0;
-		processed = stats->indexed_objects = 0;
+		stats->indexed_objects = 0;
 		stats->total_objects = total_objects;
 
 		if ((error = do_progress_callback(idx, stats)) != 0)
@@ -590,7 +587,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
 	/* As the file grows any windows we try to use will be out of date */
 	git_mwindow_free_all(mwf);
 
-	while (processed < idx->nr_objects) {
+	while (stats->indexed_objects < idx->nr_objects) {
 		git_packfile_stream *stream = &idx->stream;
 		git_off_t entry_start = idx->off;
 		size_t entry_size;
@@ -665,7 +662,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
 			goto on_error;
 
 		if (!idx->have_delta) {
-			stats->indexed_objects = (unsigned int)++processed;
+			stats->indexed_objects++;
 		}
 		stats->received_objects++;