local: send the packbuilder progress via the sideband Set a callback for the packbuilder so we can send the sideband messages to the caller, formatting them as git would.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/transports/local.c b/src/transports/local.c
index 305c71b..9dd4486 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -502,6 +502,33 @@ static int foreach_cb(void *buf, size_t len, void *payload)
}
static const char *counting_objects_fmt = "Counting objects %d\r";
+static const char *compressing_objects_fmt = "Compressing objects: %.0f%% (%d/%d)";
+
+static int local_counting(int stage, unsigned int current, unsigned int total, void *payload)
+{
+ git_buf progress_info = GIT_BUF_INIT;
+ transport_local *t = payload;
+
+ if (!t->progress_cb)
+ return 0;
+
+ if (stage == GIT_PACKBUILDER_ADDING_OBJECTS) {
+ git_buf_printf(&progress_info, counting_objects_fmt, current);
+ } else if (stage == GIT_PACKBUILDER_DELTAFICATION) {
+ float perc = (((float) current) / total) * 100;
+ git_buf_printf(&progress_info, compressing_objects_fmt, perc, current, total);
+ if (current == total)
+ git_buf_printf(&progress_info, ", done\n");
+ else
+ git_buf_putc(&progress_info, '\r');
+
+ }
+
+ if (git_buf_oom(&progress_info))
+ return -1;
+
+ return t->progress_cb(git_buf_cstr(&progress_info), git_buf_len(&progress_info), t->message_cb_payload);
+}
static int local_download_pack(
git_transport *transport,
@@ -527,6 +554,8 @@ static int local_download_pack(
if ((error = git_packbuilder_new(&pack, t->repo)) < 0)
goto cleanup;
+ git_packbuilder_set_callbacks(pack, local_counting, t);
+
stats->total_objects = 0;
stats->indexed_objects = 0;
stats->received_objects = 0;