Commit 3c337a5d3720f524387307bf443e7d7c6380a2e3

Carlos Martín Nieto 2015-05-06T13:09:00

packbuilder: report progress during deltification This is useful to send to the client while we're performing the work. The reporting function has a force parameter which makes sure that we do send out the message of 100% completed, even if this comes before the next udpate window.

diff --git a/src/pack-objects.c b/src/pack-objects.c
index 9327646..e287e33 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -893,6 +893,29 @@ static unsigned long free_unpacked(struct unpacked *n)
 	return freed_mem;
 }
 
+static int report_delta_progress(git_packbuilder *pb, uint32_t count, bool force)
+{
+	int ret;
+
+	if (pb->progress_cb) {
+		double current_time = git__timer();
+		double elapsed = current_time - pb->last_progress_report_time;
+
+		if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
+			pb->last_progress_report_time = current_time;
+
+			ret = pb->progress_cb(
+				GIT_PACKBUILDER_DELTAFICATION,
+				count, pb->nr_objects, pb->progress_cb_payload);
+
+			if (ret)
+				return giterr_set_after_callback(ret);
+		}
+	}
+
+	return 0;
+}
+
 static int find_deltas(git_packbuilder *pb, git_pobject **list,
 		       unsigned int *list_size, unsigned int window,
 		       int depth)
@@ -918,6 +941,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
 			break;
 		}
 
+		pb->nr_deltified += 1;
+		report_delta_progress(pb, pb->nr_deltified, false);
+
 		po = *list++;
 		(*list_size)--;
 		git_packbuilder__progress_unlock(pb);
@@ -1290,6 +1316,8 @@ static int prepare_pack(git_packbuilder *pb)
 		}
 	}
 
+	report_delta_progress(pb, pb->nr_objects, true);
+
 	pb->done = true;
 	git__free(delta_list);
 	return 0;
diff --git a/src/pack-objects.h b/src/pack-objects.h
index 9af5c0b..82dea81 100644
--- a/src/pack-objects.h
+++ b/src/pack-objects.h
@@ -65,6 +65,7 @@ struct git_packbuilder {
 	git_zstream zstream;
 
 	uint32_t nr_objects,
+		 nr_deltified,
 		 nr_alloc,
 		 nr_written,
 		 nr_remaining;